3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ ['mango', 'orange', 'apple'], ['abc'], ['ctp'], ['pqr', 'cst', 'dtc'], ['cbx'], ['xyz'], ['atc'], ]; foreach($data as $key => $d){ if(count($d)>1){ $mergeTo = $key; // store key where to merge to continue; // go to next item } $data[$mergeTo]["additional"][] = $d; // add value to $mergeTo unset($data[$key]); // unset the value from the main array } $data = array_values($data); // reset keys var_export($data);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 0 => 'mango', 1 => 'orange', 2 => 'apple', 'additional' => array ( 0 => array ( 0 => 'abc', ), 1 => array ( 0 => 'ctp', ), ), ), 1 => array ( 0 => 'pqr', 1 => 'cst', 2 => 'dtc', 'additional' => array ( 0 => array ( 0 => 'cbx', ), 1 => array ( 0 => 'xyz', ), 2 => array ( 0 => 'atc', ), ), ), )

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