3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $input = array( json_decode('{"name": "foo1", "other": "test"}'), json_decode('{"name": "foo2", "other": "test"}'), json_decode('{"name": "foo3", "other": "test"}'), ); $name = 'foo2'; echo "INPUT\n", str_repeat('=', 20), "\n"; var_dump($input); echo "\n"; echo "RESULT\n", str_repeat('=', 20), "\n"; var_dump( $result = array_filter($input, function($o) use ($name) { return $o->name == $name; }) ); echo "usage\n", str_repeat('=', 20), "\n"; $match = array_pop($result); var_dump($match->other);
based on gS0n2
Output for 5.3.0 - 7.2.0
INPUT ==================== array(3) { [0]=> object(stdClass)#1 (2) { ["name"]=> string(4) "foo1" ["other"]=> string(4) "test" } [1]=> object(stdClass)#2 (2) { ["name"]=> string(4) "foo2" ["other"]=> string(4) "test" } [2]=> object(stdClass)#3 (2) { ["name"]=> string(4) "foo3" ["other"]=> string(4) "test" } } RESULT ==================== array(1) { [1]=> object(stdClass)#2 (2) { ["name"]=> string(4) "foo2" ["other"]=> string(4) "test" } } usage ==================== string(4) "test"
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/pn6lr on line 18
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/pn6lr on line 18
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/pn6lr on line 18
Process exited with code 255.