Re: arrays question
| From: | Brent Baisley | Date: | Fri, 11 Nov 2005 21:56:18 +0000 |
| Subject: | Re: arrays question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-225654@lists.php.net to get a copy of this message | ||
Here's a few loops that should work. You can actually just use the first loop to concatenate text string instead create array items, but I wasn't sure what type of processing you wanted to do with the result.
//Convert Array from 3 rows by 2 cols -> 2 rows by 3 cols
for($i=0; $i<count($mainArray); $i++ ) {
for ( $x=0; $x<count($mainArray[$i]); $x++ ) {
$resultArray[$x][] = $mainArray[$i][$x];
}
}
Resulting Array
Array
(
[0] => Array
(
[0] => 1
[1] => 492
[2] => 11
)
[1] => Array
(
[0] => 2
[1] => 211
[2] => 20
)
)
//Convert array items to text string with "," separator
for($i=0; $i<count($resultArray); $i++) {
$resultArray[$i] = '"'.implode('","',$resultArray[$i]).'"';
}
Resulting Array:
Array
(
[0] => "1","492","11"
[1] => "2","211","20"
)
On Nov 11, 2005, at 3:25 PM, cybermalandro cybermalandro wrote:
I have this that looks like this array(3) { [0]=> array(2) {-- Brent Baisley Systems Architect Landover Associates, Inc. Search & Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577[0]=> string(1) "1" [1]=> string(1) "2"} [1]=> array(2) {[0]=> string(3) "492" [1]=> string(3) "211"} [2]=> array(2) {[0]=> string(2) "11" [1]=> string(2) "20"} } I want to loop through so I can get and print "1","492","11" and "2","211","20" What is the best way to do this? I suck with arrays and I can't get my looping right. Thanks for your help anybody!