Hi, I need to add some new values to array by doing something similar.
$array = array();
$array[7] = 'test1';
$array[7] = 'test2';
The problem is that [7] only takes the last value that was added and not test1. Thanks for any help.
Hi, I need to add some new values to array by doing something similar.
$array = array();
$array[7] = 'test1';
$array[7] = 'test2';
The problem is that [7] only takes the last value that was added and not test1. Thanks for any help.
Declare a new (sub)array at the desired offset, and use []
to append new elements to it:
$array = array();
$array[7] = array();
$array[7][] = 'test1';
$array[7][] = 'test2';
print_r($array);