php - Convert string to multdimensional array
Get the solution ↓↓↓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: sqlstate[23000]: integrity constraint violation: 1452 cannot add or update a child row: a foreign key constraint fails
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.