Re: Re[2]: [PHP] split array in 2 halfs

From: Date: Wed, 31 Oct 2001 21:53:59 +0000
Subject: Re: Re[2]: [PHP] split array in 2 halfs
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-73081@lists.php.net to get a copy of this message
Correction: $count = count($array); $count = $count/2; $count = round($count,0); "Liz Fulghum" <efulghum@nospam.me.inter-tek.net> wrote in message news:20011031215118.65493.qmail@pb1.pair.com... > You could also grab the midpoint of the array: > > $count = round(count($array), 0); > > then populate your new arrays by using a foreach loop: > > $x = 0; > foreach($array as $key => $value) { > if ($x <=$count) { > $array1[] = $value; > } else { > $array2[] = $value; > } > $x++; > } > > > > "Daniel Harik" <gatop@hot.ee> wrote in message > news:11752292412.20011031232555@hot.ee... > > Want to split it in half > > > > 1 Big array: > > > > 1 > > 2 > > 3 > > 4 > > 5 > > 6 > > > > Want to make > > > > > > 1 Small array: > > > > 1 > > 2 > > 3 > > > > 2 Small array: > > 4 > > 5 > > 6 > > > > Thank You > > > >

« previous php.general (#73081) next »