Page 1 of 1

implode multidim array [solved]

Posted: Wed Jan 16, 2008 11:11 pm
by lafflin
hello, I am tryin to do something that I'm sure any experienced php programmer (which I am not) can do without thought.

I have a multidim array, two dimensions, the first is the name, price, qty, and total of an item,
It is nested into another array , we'll call it $line_item. now each product has it's own line when I print it out to the screen if I print the arrays to the screen.

But I don't want to print them to the screen, I want to be able to use all the values in a function called fpdf which takes a string or a variable representing a string as the parameter for creating a pdf (my reciept).

so here is what I have came up with so far:

Code: Select all

 
function breakdown() {
                         foreach ($_SESSION['sale_info'] as $si) {
                         return (implode("\t",$si) ); } ;}
 
The result of this is that I get only the first line item displayed in my pdf.

I am a beginner and I am putting alot of effort in before just posting and saying how do you do this, I have been reading the manual extensively.
This could be completely the wrong approach to getting these values from this array, and if it is please feel free to do it any other way that you feel is better, all sugestions are greatly appreciated.

Re: implode multidim array

Posted: Wed Jan 16, 2008 11:13 pm
by lafflin
also I am outting my code between

Code: Select all

tags, where are the

Code: Select all

tags?

Re: implode multidim array

Posted: Wed Jan 16, 2008 11:18 pm
by jimthunderbird
Can you briefly give me your array's structure in code. Just sample data is fine.

Re: implode multidim array

Posted: Wed Jan 16, 2008 11:40 pm
by Zoxive
Close..

Code: Select all

function breakdown() {
  $Tmp='';
  foreach ($_SESSION['sale_info'] as $si) {
    $Tmp.= implode("\t",$si); 
  }
  return $Tmp;
}
Your version you were only returning the 1st loop implode.

Code: Select all

is how to get PHP highlighting.

Re: implode multidim array

Posted: Wed Jan 16, 2008 11:43 pm
by jimthunderbird
Yeah that's correct. +1 for Zoxive.

Re: implode multidim array

Posted: Thu Jan 17, 2008 12:00 am
by lafflin
Zox, jim, am so greatful! So so grateful! Thank you so much. I was so stuck on that I forgot what I was going to do next, but thanks, that was a huge hump you just got me over.