3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $post = [ 'id_228' => 228, 'title_228' => "First", 'colour_228' => 'red', 'id_229' => 228, 'title_229' => "Second", 'colour_229' => 'blue']; // Transform data into a proper format $resultArray = []; foreach($post as $key => $val) { $key = explode('_',$key); $resultArray[$key[1]][$key[0]] = $val; } // Now do whatever you want to do var_dump($resultArray);
based on EPTMI
Output for 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.30 - 7.3.0alpha1
array(2) { [228]=> array(3) { ["id"]=> int(228) ["title"]=> string(5) "First" ["colour"]=> string(3) "red" } [229]=> array(3) { ["id"]=> int(228) ["title"]=> string(6) "Second" ["colour"]=> string(4) "blue" } }