Re: Implode a 2D Array

From: Date: Thu, 02 Jul 2009 21:18:42 +0000
Subject: Re: Implode a 2D Array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-294837@lists.php.net to get a copy of this message
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

« previous php.general (#294837) next »