3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = '1,Home,3,Services,6,Service 1,7,Service 2,2,Products'; $keysAndValues = explode(',', $input); $result = []; $count = count($keysAndValues); for ($i = 0; $i < $count; $i+=2) { $key = $keysAndValues[$i]; $value = $keysAndValues[$i+1]; $result[$key] = $value; } var_dump($result);

preferences:
25.79 ms | 405 KiB | 5 Q