[thelist] Php array, best way to...

jsWalter jsWalter at torres.ws
Sat Jul 10 04:15:34 CDT 2004


I have an array with 100+ elements

Each element is an array of 75 elements

What would be the best way to retrieve a subset of elements from each
the sub-array?

Say I wanted element 2 thru 6, 11 and 42 from each element of the main
array?

How would you go about this?

============

Now to ask the question using terms like 'row' and column'.

Yes, I know, PHP arrays are not rows and columns. They are index arrays
that can hold arrays in each "value" of the array.

I want column 2 thru 6, 11 and 42 from each row.

How would you go about this?

=============

Right now, I pull each element out and stick it in a second array...

  $tmpArray = array()

   for ( $i = 0; $i < $mainArrayCount; $i++ )
   {
      $tmpArray [$i][] = $rec[2];
      $tmpArray [$i][] = $rec[3];
      $tmpArray [$i][] = $rec[4];
      $tmpArray [$i][] = $rec[5];
      $tmpArray [$i][] = $rec[6];
      $tmpArray [$i][] = $rec[11];
      $tmpArray [$i][] = $rec[42];
   }

Is there a better way?

Thanks

Walter




More information about the thelist mailing list