associative arrays

how do i assign multiple values to multiple elements?

ex.

$price = array(“item” => 10, 15, 16 => “item2” => 13, 14, 15);

i thought this would work, but when i try to show something like:

item costs 10, 15, 16. item2 costs 13, 14, 15.

instead i get:

item costs 10. 0 costs 15. 1 costs 16. item2 costs 13. 2 costs 14. 3 costs 15.

the , seperates the values. Leavin "xxx"=> just makes a numerric key
[php]$price = array(“item” => 10, 15, 16, “item2” => 13, 14, 15); [/php]is the same as[php]$price = array(“item” => 10, 0 => 15, 1 => 16, “item2” => 13, 2 => 14, 3 => 15); [/php]
u need a multidimensional array.
[php]$price = array(“item” => array(10, 15, 16) => “item2” => array(13, 14, 15)); [/php]
and then u may use implode
[php]echo implode(’, '$price[“item”]);[/php]

P.S.: read the chapter about arrays in the php-man again ( http://php.net/manual )

Sponsor our Newsletter | Privacy Policy | Terms of Service