Compress if with array

1

I have the following code that I want to "compress" or simplify Could it be done with an array?

<?php if ($row['tecnico'] == $_SESSION['username'] or 
   $_SESSION['username'] == "nameA" or 
   $_SESSION['username'] == "nameB" or 
   $_SESSION['username'] == "nameC" or 
   $_SESSION['username'] == "nameD") : ?>
    
asked by Tefef 30.10.2018 в 19:01
source

1 answer

2

You could create an array with the options you need and use in_array like this:

<?php $opciones = array('nameA', 'nameB', 'nameC', 'nameD');

if ($row['tecnico'] == $_SESSION['username'] or in_array($_SESSION['username'], $opciones)) : ?>
    
answered by 30.10.2018 / 19:05
source