I have array $array["rlist"] that outputs:
Array (
[0] => Array ( [0] => test1 )
[1] => Array ( [0] => test2 )
[2] => Array ( [0] => test3 )
[3] => Array ( [0] => test4 )
[4] => Array ( [0] => test5 )
)
When I try to edit like so:
$array["rlist"][0][0] = 'test1';
$array["rlist"][0][1] = 'test2';
$array["rlist"][0][2] = 'test3';
$array["rlist"][0][3] = 'test4';
$array["rlist"][0][4] = 'test5';
I get
Array (
[0] => Array (
[0] => test1
[1] => test2
[2] => test3
[3] => test4
[4] => test5
)
)
What am I doing wrong?
4
Answers
it’s expected because the element is in
so if you want to edit then:
If you format your original output, you would see the proper formatting you need…
You can achieve this by setting each item seprately…
or set them in 1 chunk…
You have an array like this:
The key is [$i++] and the value is an array, so you can edit like this :
To avoid handwriting the 2d structure of single-element rows, you can hydrate a flat array with
array_chunk()
with 1 element per chunk.Code: (Demo)
Although it is not clear why you need to edit your array.