3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 0 => [ 'id' => 20, 'name' => 'Test' ], 1 => [ 'id' => 20, 'name' => 'Test1' ], 2 => [ 'id' => 12, 'name' => 'Test2' ], 3 => [ 'id' => 24, 'name' => 'Test3' ] ]; $arr = $currentValue = $previousValue = ['id' => '']; foreach($array as $key => $value) { $currentValue = [ 'id' => $previousValue['id'] === $value['id'] ? '' : $value['id'], 'name' => $value['name'] ]; $arr[] = $previousValue = $currentValue; } var_dump($arr);
Output for git.master, git.master_jit, rfc.property-hooks
array(5) { ["id"]=> string(0) "" [0]=> array(2) { ["id"]=> int(20) ["name"]=> string(4) "Test" } [1]=> array(2) { ["id"]=> string(0) "" ["name"]=> string(5) "Test1" } [2]=> array(2) { ["id"]=> int(12) ["name"]=> string(5) "Test2" } [3]=> array(2) { ["id"]=> int(24) ["name"]=> string(5) "Test3" } }

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