3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['name'=>'Strawberry','id'=>'10'], ['id'=>'13'], ['name'=>'Apple','id'=>'20'], ['id'=>'28'], ['name'=>'Mandarin','id'=>'30'], ['name'=>'Apple','id'=>'50'], ['name'=>'Strawberry','id'=>'60'], ]; $tmp_arr = []; foreach( $array as $element ) { if( array_key_exists('name', $element) ) { $tmp_arr[$element['name']][] = $element; } else { $tmp_arr[] = [$element]; } } var_dump($tmp_arr); $array = call_user_func_array('array_merge', $tmp_arr); var_dump($array);
Output for git.master, git.master_jit, rfc.property-hooks
array(5) { ["Strawberry"]=> array(2) { [0]=> array(2) { ["name"]=> string(10) "Strawberry" ["id"]=> string(2) "10" } [1]=> array(2) { ["name"]=> string(10) "Strawberry" ["id"]=> string(2) "60" } } [0]=> array(1) { [0]=> array(1) { ["id"]=> string(2) "13" } } ["Apple"]=> array(2) { [0]=> array(2) { ["name"]=> string(5) "Apple" ["id"]=> string(2) "20" } [1]=> array(2) { ["name"]=> string(5) "Apple" ["id"]=> string(2) "50" } } [1]=> array(1) { [0]=> array(1) { ["id"]=> string(2) "28" } } ["Mandarin"]=> array(1) { [0]=> array(2) { ["name"]=> string(8) "Mandarin" ["id"]=> string(2) "30" } } } Fatal error: Uncaught Error: Cannot use positional argument after named argument in /in/BS6Jc:24 Stack trace: #0 {main} thrown in /in/BS6Jc on line 24
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:
54.33 ms | 402 KiB | 8 Q