3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sqlRows = []; $sqlRows[] = ['id' => 1,'depart_kode' => '001', 'depart_task' => 'task', 'value' => 'value']; $sqlRows[] = ['id' => 2,'depart_kode' => '001.12', 'depart_task' => 'task', 'value' => 'value']; $sqlRows[] = ['id' => 3,'depart_kode' => '001.452', 'depart_task' => 'task', 'value' => 'value']; $sqlRows[] = ['id' => 4,'depart_kode' => '002.914', 'depart_task' => 'task', 'value' => 'value']; $sqlRows[] = ['id' => 5,'depart_kode' => '002', 'depart_task' => 'task', 'value' => 'value']; $sqlRows[] = ['id' => 6,'depart_kode' => '003', 'depart_task' => 'task', 'value' => 'value']; $departs = []; foreach ($sqlRows as $row) { $departKey = substr($row['depart_kode'], 0, 3); if (!array_key_exists($departKey, $departs)) { $departs[$departKey] = []; } $departs[$departKey][] = $row['depart_kode']; } var_dump($departs);
Output for git.master, git.master_jit, rfc.property-hooks
array(3) { ["001"]=> array(3) { [0]=> string(3) "001" [1]=> string(6) "001.12" [2]=> string(7) "001.452" } ["002"]=> array(2) { [0]=> string(7) "002.914" [1]=> string(3) "002" } ["003"]=> array(1) { [0]=> string(3) "003" } }

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