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
Share on other sites

Sweeeeet!

 

Just one more thingy.

 

How do I display the

 

[0] or the [1] etc... part of this:

[0] => Array

 

I think it's the $key but for the purpose of unseting peices of the array i need to identify that value.

Link to comment
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.