3v4l.org

run code in 300+ PHP versions simultaneously
<?php function multi_array_search($search_for, $search_in) { foreach ($search_in as $element) { echo "searching " . json_encode($element) . "\n"; if ( ($element === $search_for) ){ return true; }elseif(is_array($element)){ $result = multi_array_search($search_for, $element); if($result == true) return true; } } return false; } $my_array = array( 0 => array( "name" => "john", "id" => 4 ), 1 => array( "name" => "mark", "id" => 152 ), 2 => array( "name" => "Eduard", "id" => 152 ) ); echo multi_array_search(152, $my_array) ? 'Found' : 'Not found';
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 8.0.0 - 8.0.12, 8.1rc1 - rc3
searching {"name":"john","id":4} searching "john" searching 4 searching {"name":"mark","id":152} searching "mark" searching 152 Found

preferences:
36.34 ms | 460 KiB | 5 Q