3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Example 1 -- Unpacking the array to do work on it array_map(function ($x) { $first_name = $x[0]; $last_name = $x[1]; // Do important work here with first_name and last_name... // But $first_name and $last_name are scoped to this function // See the second example for how we'd inject an anonymous function to operate with $first_name and $last_name }, [ ['John', 'Galt'], ['Howard', 'Roark'], ]); // Example 2 -- Separation of input setup and behavior $behavior = function ($first_name, $last_name) { var_dump('Doing hard work!', $first_name, $last_name); }; array_map(function ($x) use ($behavior) { $first_name = $x[0]; $last_name = $x[1]; // $behavior is invoked using our unpacked arguments $behavior($first_name, $last_name); }, [ ['John', 'Galt'], ['Howard', 'Roark'], ]);
Output for git.master, git.master_jit, rfc.property-hooks
string(16) "Doing hard work!" string(4) "John" string(4) "Galt" string(16) "Doing hard work!" string(6) "Howard" string(5) "Roark"

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:
29.98 ms | 405 KiB | 5 Q