3v4l.org

run code in 300+ PHP versions simultaneously
<?php function reindexWeeks($sourceWeeks, &$destWeeks, &$idxNew) { foreach($sourceWeeks as $sourceKey => $sourceValue) { if (is_array($sourceValue)) { $destWeeks[$idxNew] = array(); reindexWeeks($sourceValue, $destWeeks[$idxNew], $idxNew); } else { $destWeeks[$idxNew] = $sourceValue; $idxNew++; } } } $idxNew = 1; // starting index. $newWeeks = array(); // output array at the 'week' level $month = array ( 'weeks'=> array( 'w1'=> array( 'd1'=> 'day one', 'd2'=> 'day two', 'd3'=> array( 'H1' => 'hour one', 'H2' => 'hour two' ) ), 'w2'=> array( 'd1'=> 'day one', 'd2'=> 'day two' ) ) ); reindexWeeks($month['weeks'], $newWeeks, $idxNew); // re-index the array print_r($newWeeks);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [1] => Array ( [1] => day one [2] => day two [3] => Array ( [3] => hour one [4] => hour two ) ) [5] => Array ( [5] => day one [6] => day two ) )

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:
41.8 ms | 402 KiB | 8 Q