3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data=array(array('name'=>'ahmed','job'=>'engineer','age'=>25,'hobbies'=>array('drawing','swimming','reading'),'skills'=>array('coding','fasting learning','teaching')),array('name'=>'Sara','job'=>'designer','age'=>19,'skills'=>array('fast learning')),array('name'=>'Ali','age'=>25,'city'=>'cairo'),array('name'=>'Hossam','job'=>'accountant','age'=>25,'city'=>'zagazig'),array('name'=>'Esraa','job'=>'Designer','age'=>23,'city'=>'zagazig','hobbies'=>array('writing','reading'),'skills'=>array('coding','teaching')),); $search_string = 'zagazig'; $results = array(); foreach($data as $value) { if( !empty($value['city']) && (stripos($value['city'], $search_string) !== false) ) { $results[] = $value; } } if(!empty($results)) { echo 'Number of results: ' , count($results), PHP_EOL, ' Result ', PHP_EOL; foreach($results as $r) { echo " Name: {$r['name']} Job: {$r['job']} Age: {$r['age']} ", PHP_EOL; echo !empty($r['hobbies']) ? PHP_EOL . 'Hobbies: ' . PHP_EOL . implode(PHP_EOL, $r['hobbies']) : ''; } }
Output for 5.6.0 - 5.6.25, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Number of results: 2 Result Name: Hossam Job: accountant Age: 25 Name: Esraa Job: Designer Age: 23 Hobbies: writing reading
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Number of results: 2 Result Name: Hossam Job: accountant Age: 25 Name: Esraa Job: Designer Age: 23 Hobbies: writing reading

preferences:
172.84 ms | 402 KiB | 214 Q