implode multidim array [solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

implode multidim array [solved]

Post 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.
Last edited by lafflin on Thu Jan 17, 2008 12:01 am, edited 1 time in total.
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

Re: implode multidim array

Post by lafflin »

also I am outting my code between

Code: Select all

tags, where are the

Code: Select all

tags?
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Re: implode multidim array

Post by jimthunderbird »

Can you briefly give me your array's structure in code. Just sample data is fine.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: implode multidim array

Post 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.
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Re: implode multidim array

Post by jimthunderbird »

Yeah that's correct. +1 for Zoxive.
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

Re: implode multidim array

Post 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.
Post Reply