create an array from a string that has a multiple occurances of a certain string PHP
Get the solution ↓↓↓Solution:
Here is the solution, a bit messy, but works:
<?php
$string = "category=123&code=456&type=type111&type=type222";
$repeated_key = 'type';
$variable = explode('&', $string);
$data_o = array();
foreach ($variable as $key0 => $value0) {
$subvariable = explode('=', $value0);
if($subvariable[0] == $repeated_key){
continue;
}
$data_o[$subvariable[0]] = $subvariable[1];
}
$i=0;
foreach ($variable as $key1 => $value1) {
$subvariable = explode('=', $value1);
if($subvariable[0] != $repeated_key){
continue;
}
$data_t = array();
$data_t['type'] = $subvariable[1];
$data[] = array_merge($data_o,$data_t);
$i++;
}
echo "<pre>";
print_r($data);
exit;
?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: please make sure the php redis extension is installed and enabled.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.