3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myWondersArray = array ( 0 => (object) array( 'currentUnitDisplay' => 'WonderSkills: Starter Book 2, Unit 3 - Helping Mom (Part 1/3)', 'currentUnitPart' => 'wonderskills/starter_book_2/unit_3_helping_mom/part_1/', ), 1 => (object) array( 'currentUnitDisplay' => 'WonderSkills: Starter Book 2, Unit 3 - Helping Mom (Part 2/3)', 'currentUnitPart' => 'wonderskills/starter_book_2/unit_3_helping_mom/part_2/', ), 2 => (object) array( 'currentUnitDisplay' => 'WonderSkills: Starter Book 2, Unit 3 - Helping Mom (Part 3/3)', 'currentUnitPart' => 'wonderskills/starter_book_2/unit_3_helping_mom/part_3/', ), 3 => (object) array( 'previousUnitDisplay' => 'WonderSkills: Starter Book 2, Unit 2 - Sid\'s New Neighbors (Part 1/3)', 'previousUnitPart' => 'wonderskills/starter_book_2/unit_2_sids_new_neighbors/part_1/', ), 4 => (object) array( 'previousUnitDisplay' => 'WonderSkills: Starter Book 2, Unit 2 - Sid\'s New Neighbors (Part 2/3)', 'previousUnitPart' => 'wonderskills/starter_book_2/unit_2_sids_new_neighbors/part_2/', ), 5 => (object) array( 'previousUnitDisplay' => 'WonderSkills: Starter Book 2, Unit 2 - Sid\'s New Neighbors (Part 3/3)', 'previousUnitPart' => 'wonderskills/starter_book_2/unit_2_sids_new_neighbors/part_3/', ), 6 => (object) array( 'nextUnitDisplay' => 'WonderSkills: Starter Book 2, Unit 4 - Food from the Garden (Part 1/3)', 'nextUnitPart' => 'wonderskills/starter_book_2/unit_4_food_from_the_garden/part_1/', ), 7 => (object) array( 'nextUnitDisplay' => 'WonderSkills: Starter Book 2, Unit 4 - Food from the Garden (Part 2/3)', 'nextUnitPart' => 'wonderskills/starter_book_2/unit_4_food_from_the_garden/part_2/', ), 8 => (object) array( 'nextUnitDisplay' => 'WonderSkills: Starter Book 2, Unit 4 - Food from the Garden (Part 3/3)', 'nextUnitPart' => 'wonderskills/starter_book_2/unit_4_food_from_the_garden/part_3/', ), ); $buckets = array_fill_keys(['previous', 'current', 'next'], []); foreach ($myWondersArray as $obj) { $buckets[substr(key((array) $obj), 0, -11)][] = $obj; } var_export(array_merge(...array_values($buckets)));

preferences:
24.57 ms | 409 KiB | 5 Q