php - Convert string to multdimensional array

Solution:
I just got it, as follows:
private function createArrayFromString($fields)
{
$arrayFields = [];
foreach ($fields as $k => $field) {
$field = explode('.', $field);
$count = count($field);
if ($count > 1) {
$parent = $field[0];
unset($field[0]);
$nextFields[] = implode('.', $field);
$arrayFields[$parent] = $this->createArrayFromString($nextFields);
} else {
$arrayFields[$k] = $field[0];
}
}
return $arrayFields;
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: an exception occurred in the driver: could not find driver
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.