change the array name in array with array_push

advertisements

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


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.