3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ "1" => [ "book" => "Harry Potter", "artist" => array("David", "Emma"), "country" => [ ["description" => "Wander"], ["description" => "Magic"] ] ], "2" => [ "book" => "Science book", "artist" => array("Artist 1", "Melanie Hudson"), "country" => [ ["description" => "Physics"], ["description" => "Albert Einstein"] ] ], "3" => [ "book" => "Bible", "artist" => array("Artist 1", "Pedro"), "country" => [ ["description" => "Love"], ["description" => "Respect"] ] ], ]; $result = []; // $result is container for matches - filled by reference $needle = 'Wander'; // the key we are looking for recurse($data, $needle, $result); function recurse($haystack = [], $needle = '', &$result) { foreach($haystack as $key => $value) { if(is_array($value)) { recurse($value, $needle, $result); } else { if(strpos($value, $needle) !== false) { $result[] = $value; // store match } } } } echo '<pre>'; var_dump($result); echo '</pre>';
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Optional parameter $haystack declared before required parameter $result is implicitly treated as a required parameter in /in/E6LT6 on line 34 Deprecated: Optional parameter $needle declared before required parameter $result is implicitly treated as a required parameter in /in/E6LT6 on line 34 <pre>array(1) { [0]=> string(6) "Wander" } </pre>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
36.15 ms | 406 KiB | 5 Q