3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'de' => [ 'label' => 'German', 'id' => 912 ], 'cn' => [ 'label' => 'Chinese', 'id' => 913 ] ]; // Initial attempt $translations = array_map( function ($v) { return $v['label']; }, $input ); var_dump($translations); // Actual //[ // 0 => [ // 'de' => 'German' // ], // 1 => [ // 'cn' 'Chinese' // ] //] // Desired //[ // 'de' => 'German', // 'cn' => 'Chinese' //] // Works declaratively via the following... $newArray = []; foreach ($array as $key => $value) { $newArray[$key] = $value['label']; } var_dump($newArray);
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined variable $input in /in/5WLj8 on line 19 Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array, null given in /in/5WLj8:15 Stack trace: #0 /in/5WLj8(15): array_map(Object(Closure), NULL) #1 {main} thrown in /in/5WLj8 on line 15
Process exited with code 255.

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:
58.06 ms | 401 KiB | 8 Q