3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ ['id'=> 1,'name'=>'イワーク','place'=>'渓谷,洞窟','level' => 10,'technique'=>'岩雪崩'], ['id'=> 1,'name'=>'イワーク','place'=>'砂漠,山頂','level' => 20,'technique'=>'岩石砲'], ['id'=> 2,'name'=>'ハガネール','place'=>'鉱山,地中','level' => 10,'technique'=>'メテオドライブ'], ['id'=> 2,'name'=>'ハガネール','place'=>'丘陵,窪地','level' => 20,'technique'=>'アイアンローラー'], ]; $places = array_reduce($data, function ($carry, $item) { ['id' => $id, 'level' => $level, 'technique' => $technique] = $item; array_push($carry[$id]['place_list'], ...explode(',', $item['place'])); $carry[$id]['lv_list'][$level] = compact('level', 'technique'); return $carry; }, array_map(fn($a) => ['id' => $a['id'], 'name' => $a['name'], 'place_list' => [], 'lv_list' => []], array_column($data, null, 'id'))); var_dump($places);
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { [1]=> array(4) { ["id"]=> int(1) ["name"]=> string(12) "イワーク" ["place_list"]=> array(4) { [0]=> string(6) "渓谷" [1]=> string(6) "洞窟" [2]=> string(6) "砂漠" [3]=> string(6) "山頂" } ["lv_list"]=> array(2) { [10]=> array(2) { ["level"]=> int(10) ["technique"]=> string(9) "岩雪崩" } [20]=> array(2) { ["level"]=> int(20) ["technique"]=> string(9) "岩石砲" } } } [2]=> array(4) { ["id"]=> int(2) ["name"]=> string(15) "ハガネール" ["place_list"]=> array(4) { [0]=> string(6) "鉱山" [1]=> string(6) "地中" [2]=> string(6) "丘陵" [3]=> string(6) "窪地" } ["lv_list"]=> array(2) { [10]=> array(2) { ["level"]=> int(10) ["technique"]=> string(21) "メテオドライブ" } [20]=> array(2) { ["level"]=> int(20) ["technique"]=> string(24) "アイアンローラー" } } } }

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:
36.25 ms | 409 KiB | 5 Q