3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input1 = [ '0' => [ 'foo01' => 'value01', 'bar02' => 'value02', 'formats01' => [ 'subfoo_011' => 'subvalue_011', 'subfoo_012' => 'subvalue_012', ] ], '1' => [ 'foo11' => 'value11', 'bar12' => 'value12', 'formats02' => [ 'subfoo_021' => 'subvalue_021', 'subfoo_022' => 'subvalue_022', ] ] ]; $input2 = [ 'foo' => 'value1', 'bar' => 'value2', 'formats' => [ 'foo' => 'value_1', 'bar' => 'value_2', ] ]; function countValues(array $array) { $i = 0; foreach ($array as $arrayKey => $data) { $i++; $ii = 0; foreach ($data as $key => $value) { $ii++; if (!is_array($value)) { $newArray[':' . $key . '_' . $i . '_' . $ii] = $value; } else if (is_array($value)) { foreach ($value as $subKey => $subValue) { $newArray[':' . $subKey . '_' . $i . '_' . $ii] = $subValue; } } } } return $newArray; } var_dump(countValues($input1)); var_dump(countValues([$input2]));
Output for git.master, git.master_jit, rfc.property-hooks
array(8) { [":foo01_1_1"]=> string(7) "value01" [":bar02_1_2"]=> string(7) "value02" [":subfoo_011_1_3"]=> string(12) "subvalue_011" [":subfoo_012_1_3"]=> string(12) "subvalue_012" [":foo11_2_1"]=> string(7) "value11" [":bar12_2_2"]=> string(7) "value12" [":subfoo_021_2_3"]=> string(12) "subvalue_021" [":subfoo_022_2_3"]=> string(12) "subvalue_022" } array(4) { [":foo_1_1"]=> string(6) "value1" [":bar_1_2"]=> string(6) "value2" [":foo_1_3"]=> string(7) "value_1" [":bar_1_3"]=> string(7) "value_2" }

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