Re: Multi-Dimensional Arrays
| From: | Jonathan Duncan | Date: | Thu, 10 Oct 2002 15:17:49 +0000 |
| Subject: | Re: Multi-Dimensional Arrays | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-119545@lists.php.net to get a copy of this message | ||
Yeah, you rock, that works great. Not to mention you have a great name.
Jonathan Duncan
"Jonathan Sharp" <js-lists@sharpmedia.net> wrote in message
news:3DA50C47.3010609@sharpmedia.net...
> try doing this for each item:
>
> $cartArray[] = array('itemnumber' => $itemnumber, 'brand' => $brand,
> 'quantity' => $itemqty, 'name' => $itemname);
>
> -js
>
> Jonathan Duncan wrote:
> > I am trying to create an array to hold shopping cart information. The
array
> > I am using is called "cartArray". What I want to do is to define a
> > sub-array of cartArray with the information from one product. Then the
next
> > time a product is added it appends then new information as a second
> > sub-array to cartArray and so forth. Following is some code I have been
> > using to test with and so far PHP will let me use ".=" to append but
when I
> > try to call it back with "print_r" or echo array[][] only the first
entry is
> > returned. Any ideas what I am doing wrong?
> >
> > --------------------------------------------
> > $brand="Brand1";
> > $itemnumber="456789";
> > $itemname="Some Item Name";
> > $itemqty=3;
> > $cartArray[] .= array(0=>array($itemnumber=>"$brand",
> > "$itemqty",
> > "$itemname"));
> > print_r($cartArray)."<BR><BR>";
> > $brand="Brand2";
> > $itemnumber="123456";
> > $itemname="Another Item Name";
> > $itemqty=9;
> > array_push($cartArray, array($itemnumber=>"$brand", "$itemqty",
> > "$itemname"));
> > print_r($cartArray)."<BR><BR>";
> > echo $cartArray[0][0]."<BR><BR>";
> > --------------------------------------------
> >
> > Thank you,
> > Jonathan Duncan
> >
> >
> >
>
>
>