[SOLVED]limit size of array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

[SOLVED]limit size of array

Post 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.
Last edited by facets on Sun May 13, 2007 8:19 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

array_slice().
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

thanks. perfect
Post Reply