create multimentional array in php

Solution:
The problem is this line:
$new_array[$i] = $title;
This is setting the initial elements of$new_array
to strings, not an array. So when you later do
$new_array[$first_key][] = $title;
it's trying to doarray_push
on a string.
That line should be:
$new_array[$i] = array($title);
Answer
Solution:
Add this statement before the one that triggers the error:
if (!isset($new_array[$first_key])) $new_array[$first_key] = array();
This way you ensure that$new_array[$first_key]
is initialised as an array and you can safely add elements to that array.
But your algorithm will still fail, as you use that same array $new_array in your preg_grep call. That will not work as you want when you have added sub-arrays to $new_array.
You need to two variables: one for doing the preg_grep, which you do not change, and one where you add to in your loop. Currently you are mixing these two...
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: sqlstate[hy000] [1698] access denied for user 'root'@'localhost'
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.