<?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);
- Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
- array(5) {
[1]=>
string(4) "Home"
[3]=>
string(8) "Services"
[6]=>
string(9) "Service 1"
[7]=>
string(9) "Service 2"
[2]=>
string(8) "Products"
}
preferences:
134.6 ms | 407 KiB | 5 Q