create string from multidim array
Posted: Tue Jan 15, 2008 12:27 am
Hello, I am trying to create a string with several variables taken from a multidimensional array. I have my array built and I have tested it, then stuck it into a session to pass it to another script. The script recieving the $_SESSION needs to iterate through both dimensions of it.
the array is 2 dimensions, the first (left) dimension is a line item and contains an array of the individual characteristics of that line.(item, price, qty, total).
so for instance, my array, was this:
and it is contained in a loop, each item placed in the shopping cart creates another array item.
I then
and now I want to do something like this:
and I want it to look like this
shirt 12.00 2 24.00
pants 21.00 2 22.00
This last bit is where I am stuck, I want to be able to return a string full of my values seperated by tabs and one break per line as one variable
any help is appreciated!
the array is 2 dimensions, the first (left) dimension is a line item and contains an array of the individual characteristics of that line.(item, price, qty, total).
so for instance, my array, was this:
Code: Select all
$sale_info[] = array("$item","$price","$qty","$combined") ;
and it is contained in a loop, each item placed in the shopping cart creates another array item.
I then
Code: Select all
$_SESSION['sale_info'] = $sale_info ;
Code: Select all
foreach ($_SESSION['sale_info'] as $items)
{ "$items[0] \t $items[1] \t $items[2] \t $items[3] <br>"; }
shirt 12.00 2 24.00
pants 21.00 2 22.00
This last bit is where I am stuck, I want to be able to return a string full of my values seperated by tabs and one break per line as one variable
any help is appreciated!