« Return to Thread: Implode a 2D Array

Re: Implode a 2D Array

by Shawn McKenzie :: Rate this Message:

Reply to Author | View in Thread

salmarayan wrote:

> Can any one tell me how can i implode a two D Array.
> i can implode normal arrays, but when i try to implode multidimensional
> Arrays, the result is empty.
> can some one tell me how to implode an array Like This
>
>
> $x=array ( [0] => array ( [side] => sell [stock_code] => AFMC.CA [quantity]
> => 200  ) ,
> [1] => array ( [side] => buy [stock_code] => AFMC.CA [quantity] => 200 );
>
> i want to implode it in a way, the later one i can seperate rows, meaning i
> can seperate [0] from [1] and the elements in each row, like the side stock
> code using the SPLIT function.
> Thanks in Advance. :)

You'll have to be more specific in what you want the end result to be
becuse I'm confused.  You already have 0 and 1 separated.  How do you
want to glue them? Maybe you don't really want to implode() them? If you
really want to implode each one, then:

foreach($x as $array) {
        $row[] = implode(',', $array);
}

Or maybe (not tested):

$rows = array_map('implode', array_fill(0, count($x), ','), $x);



--
Thanks!
-Shawn
http://www.spidean.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

 « Return to Thread: Implode a 2D Array