Jump to content

I've almost got this Array Whipped!


phpretard

Recommended Posts

This Code Only Displays One Array Value.  Icant figure out where to put the $a++ if that is what I am Suppost to do.

 

 

$a=0;
foreach ($_SESSION as $lineItem => $val){

echo"
<table border=1 width=100%>
<tr>
	<td>
	".$_SESSION[$lineItem][$a]['Item']."
	</td>
</tr>
</table>";

}





Array
(
    [myusername] => Administrator
    [invoice_number] => 447425
    [invoice_items] => Array
        (
            [0] => Array
                (
                    [COName] => ENS Metals and Jewelry, Inc.
                    [Cnumber] => 156882
                    [Price] => 226.97
                    [Quantity] => 100
                    [item] => Tri-Fold-Brochure
                    [Description] => Full Color | Front And Back
                )

            [1] => Array
                (
                    [COName] => ENS Metals and Jewelry, Inc.
                    [Cnumber] => 156882
                    [Price] => 115.98
                    [Quantity] => 100
                    [item] => Rack-Cards
                    [Description] => Inventory Sheet
                )

            [2] => Array
                (
                    [COName] => ENS Metals and Jewelry, Inc.
                    [Cnumber] => 156882
                    [Price] => 135.98
                    [Quantity] => 100
                    [item] => Flat-Invitation
                    [Description] => Signature Cards
                )

            [3] => Array
                (
                    [COName] => ENS Metals and Jewelry, Inc.
                    [Cnumber] => 156882
                    [Price] => 175.98
                    [Quantity] => 100
                    [item] => Letterhead
                    [Description] => Welcome Letter Standard Paper
                )

        )

)

 

I need to display all of the ".$_SESSION[$lineItem][$a]['Item']."

 

Any Help?

Link to comment
https://forums.phpfreaks.com/topic/105305-ive-almost-got-this-array-whipped/
Share on other sites

Maybe a better question would be how do I unset...

 

            [3] => Array

                (

                    [COName] => ENS Metals and Jewelry, Inc.

                    [Cnumber] => 156882

                    [Price] => 175.98

                    [Quantity] => 100

                    [item] => Letterhead

                    [Description] => Welcome Letter Standard Paper

                )

 

...if I needed to.

If you use a for loop instead of a foreach loop, you have the index:

<?php
for($i=0;$i<count($_SESSION['invoice_items']);$i++) {

echo"
<table border=1 width=100%>
<tr>
	<td>
	".$_SESION['invoice_items'][$i]['Item']."
	</td>
</tr>
</table>";
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.