3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = '1_2_3_4_5'; // Get an array with 1, 2, 3, 4 and 5 $parts = explode('_', $input); $output = []; $i = 1; foreach ($parts as $part) { // array_slice() will take 1 to n elements from the array of numbers $values = array_slice($parts, 0, $i++); // Join the values $output[] = implode('_', $values); } print_r($output);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => 1 [1] => 1_2 [2] => 1_2_3 [3] => 1_2_3_4 [4] => 1_2_3_4_5 )

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