Re: Re[2]: [PHP] split array in 2 halfs
| From: | Philip Olson | Date: | Wed, 31 Oct 2001 21:53:45 +0000 |
| Subject: | Re: Re[2]: [PHP] split array in 2 halfs | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-73080@lists.php.net to get a copy of this message | ||
You may find this helpful:
$arr = array('a','b','c','d','e');
$second_half = array_splice($arr,floor(sizeof($arr)/2));
print_r($arr); // Array ( [0] => a [1] => b )
print_r($second_half); // Array ( [0] => c [1] => d [2] => e )
In the above, $second_half will be one larger then $arr if the number
of elements is odd, otherwise they'll be equally sized halves. Using
ceil() as opposed to floor() will make $second_half the smaller of the
two.
Regards,
Philip Olson
On Wed, 31 Oct 2001, Daniel Harik wrote:
> 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
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>