3v4l.org

run code in 300+ PHP versions simultaneously
<?php $ar = []; $ar['ar0']['y'] = 'Yes'; $ar['ar0']['n'] = 'No'; $ar['ar1']['g'] = 'good'; $ar['ar1']['b'] = 'bad'; $ar['ar2']['m'] = 'mom'; $ar['ar2']['d'] = 'dad'; print_r($ar); $res_ar = []; // resultant array $ar_names = []; // array of unique names foreach($ar as $ind => $row){ if (!empty($row['y']) && $row['y'] == 'Yes') $res_ar[$ind] = $row; } print_r($res_ar);
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.26, 7.4.0 - 7.4.13, 8.0.0 - 8.0.3
Array ( [ar0] => Array ( [y] => Yes [n] => No ) [ar1] => Array ( [g] => good [b] => bad ) [ar2] => Array ( [m] => mom [d] => dad ) ) Array ( [ar0] => Array ( [y] => Yes [n] => No ) )