3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = Array ( 0 => Array ( 'template_id' => 1, 'template_field_id' => 20 ), 1 => Array ( 'template_id' => 1, 'template_field_id' => 21 ), 2 => Array ( 'template_id' => 2, 'template_field_id' => 22 ), 3 => Array ( 'template_id' => 2, 'template_field_id' => 23 ) ); $resultArr = array(); foreach($arr as $data){ $index = array_search($data['template_id'], array_column($resultArr, 'id')); if($index !== false){ if(is_array($resultArr[$index]["template_fields"])) array_push($resultArr[$index]["template_fields"],array("id"=>$data["template_field_id"])); else $resultArr[$index]["template_fields"] = array(array("id"=>$data["template_field_id"])); }else{ $newData = array("id"=>$data['template_id'],"template_fields"=>array(array("id"=>$data["template_field_id"]))); array_push($resultArr,$newData); } } print_r($resultArr);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [id] => 1 [template_fields] => Array ( [0] => Array ( [id] => 20 ) [1] => Array ( [id] => 21 ) ) ) [1] => Array ( [id] => 2 [template_fields] => Array ( [0] => Array ( [id] => 22 ) [1] => Array ( [id] => 23 ) ) ) )

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:
177.75 ms | 407 KiB | 5 Q