Deviant Logo

PHP Arrays – how do i echo this!?

post details top
May 21st, 2010
post details top


Alright i have been given this array as an assignment:

$products = array(‘Jacket’ => array(‘Rain Coat’,'19.95′,’10.00′),
‘TV Stand’=> array(‘TV Unit’,'99.50′,’9.95′),
‘Computer’ => array(‘Laptop’,'425.99′, ‘48.30′));

What I need to do is to echo these values 99.50, 19.95 and 425.99. I want to know how to do that. I have tried doing this

echo $products[0][1];

and things along those line but it doesn’t echo out as i expect.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

1 Comment

  • Chris G

    Try something like this:
    —–
    < ?php
    echo "

      “;
      foreach ($products as $k => $v) {
        echo “
    • ” . $k;
        echo “
        “;
          echo “
      • ” . $v[1] . “
      • “;
          echo “

      “;
        echo “

    • “;
      }
      echo ““;
      ?>

Leave a Reply

Search

  • Partner links