Re: [PHP] arrays question

2005-11-12 Thread Brian V Bonini
On Fri, 2005-11-11 at 15:25, cybermalandro cybermalandro wrote:
 I have this that looks like this
 
 array(3) {
   [0]=
   array(2) {
 [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.

$a = array(array(1,2),
   array(492,211),
   array(11,20)
 );

for($i=0;$i2;$i++) {
foreach($a as $v) {
echo $v[$i] . \n;
}

echo ==\n;
}

Prints:

1
492
11
==
2
211
20
==


-Brian
-- 

s/:-[(/]/:-)/g


BrianGnuPG - KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu
==
gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC
Key Info: http://gfx-design.com/keys
Linux Registered User #339825 at http://counter.li.org

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



[PHP] arrays question

2005-11-11 Thread cybermalandro cybermalandro
I have this that looks like this

array(3) {
  [0]=
  array(2) {
[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!


Re: [PHP] arrays question

2005-11-11 Thread Brent Baisley
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; $icount($mainArray); $i++ ) {
for ( $x=0; $xcount($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; $icount($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) {
[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!



--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search  Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

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