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

2001-10-31 Thread Matthew Loff


More generally, this should work:

$smallarray1=array_slice($bigarray, 0, sizeof($bigarray) / 2);
$smallarray2=array_slice($bigarray, sizeof($bigarray) / 2);

I haven't tested it though...

-Original Message-
From: Mark [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, October 31, 2001 4:32 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re[3]: [PHP] split array in 2 halfs


$smallarray1=array_slice($bigarray,0,3);
$smallarray2=array_slice($bigarray,3,3);

On Wed, 31 Oct 2001 23:25:55 -0800, 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
>
>


-- 
Mark, [EMAIL PROTECTED] on 10/31/2001



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-10-31 Thread Liz Fulghum

Correction:

$count = count($array);
$count = $count/2;
$count = round($count,0);


"Liz Fulghum" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-10-31 Thread Philip Olson

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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-10-31 Thread Liz Fulghum

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" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-10-31 Thread DL Neil

Or do you really want: First array:
1
3
5

Second array
2
4
6

Corresponding to the two columns across the screen, and controlled by the same 
iteration index?
=dn

- Original Message - 
From: "Daniel Harik" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: 01 November 2001 07:25
Subject: Re[2]: [PHP] split array in 2 halfs


> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-10-31 Thread Mike Frazer

Don't forget that you should clear out that memory space, especially if it's
an array of arrays or an array of objects or something along those lines:

unset($bigarray);

Just good programming practice, that's all.  I doubt it would ever be a
problem on today's servers, but it's still a good idea.

Mike



"Mark" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
$smallarray1=array_slice($bigarray,0,3);
$smallarray2=array_slice($bigarray,3,3);

On Wed, 31 Oct 2001 23:25:55 -0800, 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
>
>


--
Mark, [EMAIL PROTECTED] on 10/31/2001





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-10-31 Thread Mark

$smallarray1=array_slice($bigarray,0,3);
$smallarray2=array_slice($bigarray,3,3);

On Wed, 31 Oct 2001 23:25:55 -0800, 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
>
>


--
Mark, [EMAIL PROTECTED] on 10/31/2001



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-10-31 Thread Jim Lucas

take a look at the manual 
http://www.php.net/manual/en/function.array-slice.php  
it will show you the right way to do it

jim
- Original Message - 
From: "Daniel Harik" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 31, 2001 11:25 PM
Subject: Re[2]: [PHP] split array in 2 halfs


> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-10-31 Thread Daniel Harik

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] split array in 2 halfs

2001-10-31 Thread Jack Dempsey

Based on what criteria? if you just want to split the array at element 30,
you could use array_splice to get the necessary data...
- Original Message -
From: "Daniel Harik" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, November 01, 2001 2:16 AM
Subject: [PHP] split array in 2 halfs


> Good evening
>
> I was wondering how can I split, array that has 60 elements in it,
> into 2 arrays with 30 elements each?
>
>
> Thank You very much and have a good night :-)
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] split array in 2 halfs

2001-10-31 Thread Daniel Harik

Good evening

I was wondering how can I split, array that has 60 elements in it,
into 2 arrays with 30 elements each?


Thank You very much and have a good night :-)


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]