i have a string it looks like this:
brand[split]bmw[split]year[split]2008[split]model[split]730D
I want it to convert to an array that looks like this:
Array ( [brand] => bmw [year] => 2008 [model] => 730D )
is there any easy way to do this?
explode() will split a string into an array of pieces:
$string = "brand[split]bmw[split]year[split]2008[split]model[split]730D";
$array = explode("[split]", $string);
Then you want to join the first to the second, third to the fourth etc:
for ($i = 0; $i < count($array); $i++) {
$result[$array[$i]] = $array[$i+1];
$i++;
}
This returns:
array:3 [▼
"brand" => "bmw"
"year" => "2008"
"model" => "730D"
]
Array ( [0] => Array ( [brand] => bmw ) [1] => Array ( [year] => 2008 ) [2] => Array ( [model] => 730D ) [3] => Array ( [] => ) [4] => Array ( [] => ) [5] => Array ( [] => ) )$i++ inside the for loop, but I'm not sure how to $i+2 in the third expression :s