3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array ( 'relation' => 'AND', 'key1' => 'Demo', 'value1' => 'demo', 'compare1' => '=', 'type1' => 'NUMERIC', 'key2' => 'test', 'value2' => 'test', 'compare2' => '=', 'type2' => 'NUMERIC', 'key3' => 'test', 'compare3' => '=', 'type3' => 'NUMERIC', 'key4' => 'test', 'value4' => 'test', 'key5' => 'test', 'value5' => 'test', 'compare5' => '=', 'type5' => 'NUMERIC', ); $new = array_splice($arr, 0,1); foreach($arr as $k => $v){ preg_match("/(.*?)(\d+)/", $k, $m); $new[$m[2]-1][$m[1]] = $v; } var_export($new);

preferences:
51.62 ms | 402 KiB | 5 Q