I have a array with a key value you on it like:
$some_array['array_key'] = "some string";
Is it possible to use array_push to add more elements to the array?
Ive tried this:
array_push($some_array['array_key'],"another string");
and I have tried other obvious way, but nothing seems to work. Is it possible to add array_push into a array with key value?
Thanks for any help you can offer,
--Bryan
You can create a multidimensional array by creating a 2-D matrix first, and then extending it. For example, first define a 3-by-3 matrix as the first page in a 3-D array. Now add a second page. To do this, assign another 3-by-3 matrix to the index value 2 in the third dimension.
Merging a multidimensional array is the same as that of a simple array. It takes two arrays as input and merges them. In a multidimensional array, the index will be assigned in increment order and will be appended after the parent array. Now, let's take the example of an employee who has two addresses.
data_type[][] array_name = new data_type[x][y]; For example: int[][] arr = new int[10][20];
If you want $some_array['array_key']
to be an array of values, you have to initialize it as an array, like this:
$some_array['array_key'] = array('some string');
Only then can you use array_push()
or the [] =
notation:
$some_array['array_key'][] = 'another string';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With