Reputation: 1
I have this code:
$array = array ('item' =>array("title" => "Revolution","size" => "100", "link" => "www"));
$add = array("title" => "Revolution","size" => "100", "link" => "www");
array_push($array, $add);
print_r ($array);
and result is this:
Array
(
[item] => Array
(
[title] => Revolution
[size] => 100
[link] => www
)
[0] => Array
(
[title] => Revolution
[size] => 100
[link] => www
)
)
How to change the [0] to [item:1], i'm lost.
Thanks Michael
Upvotes: 0
Views: 138
Reputation: 1932
I think you mean $array["items"][1]. Push to $array["items"]
instead.
Alternatively, just do $array["items"][] = arraystuff
, and it will handle the numbering for you.
Upvotes: 0
Reputation: 11106
instead of
array_push($array, $add);
write
$array['item:1'] = $add;
Upvotes: 0
Reputation: 255015
Instead of array_push
use this syntax:
$array['item:1'] = array("title" => "Revolution","size" => "100", "link" => "www");
This way you can specify the key name you want, whereas array_push
just increments the numeric index.
Upvotes: 1