Page 1 of 1

[SOLVED]limit size of array

Posted: Sun May 13, 2007 7:50 am
by facets
hi,

is it possible to limit the size of a 2d array whilst keeping everything intact?
if so could someone tell me the magic keyword?

here's my array :

Code: Select all

return $getTotalsArray;
and what it looks like from a dump.

Code: Select all

array(78) {
  [0]=>
  array(2) {
    [0]=>
    int(37)
    [1]=>
    string(7) "21406.8"
  }
  [1]=>
  array(2) {
    [0]=>
    int(104)
    [1]=>
    string(8) "11176.56"
  }
}
I wish to avoid using a for loop, if I can. Or if that's not possible some advice on rebuilding it correctly.
As the following is not correct.

Code: Select all

for ($row = 0; $row < 5; $row++) {
    	for ($col = 0; $col < 2; $col++)     {
			$toXML[] = $getTotalsArray[$row][$col];
    	}
}

Code: Select all

array(10) {
  [0]=>
  int(37)
  [1]=>
  string(7) "21406.8"
  [2]=>
  int(104)
}

tia, will.

Posted: Sun May 13, 2007 7:57 am
by Chris Corbyn
array_slice().

Posted: Sun May 13, 2007 8:19 am
by facets
thanks. perfect