On Tue, 2010-08-31 at 19:06 +0300, Tontonq Tontonq wrote:
> Ty four your all replies i got 9 replies less than 10 minutes :)
>
> than can u answer this too
> my array is like that for now
> Array
> (
> [300] => 300
> [301] => 301
> [302] => 302
> [303] => 303
> [304] => 304
> [305] => 305
> [306] => 306
> [307] => 307
> [308] => 308
> [309] => 309
> [310] => 310
> [311] => 311
> [312] => 312
> [313] => 313
> [314] => 314
> [165] => 165
> [166] => 166
> [167] => 167
> [168] => 168
> [169] => 169
> [170] => 170
> [171] => 171
> [172] => 172
> [173] => 173
> [201] => 201
> [202] => 202
> [203] => 203
> [204] => 204
> [205] => 205
> [206] => 206
> [207] => 207
> [208] => 208
> [209] => 209
> [210] => 210
> [211] => 211
> [212] => 212
> [213] => 213
> [214] => 214
> [215] => 215
> [315] => 315
>
> how can i make an array
> that will store values like
> Array
> (
> [0] => 300-314
> [1] => 165-173
> )
>
> i hope if u did understand me :D
>
> 2010/8/31 [email protected] <[email protected]>
>
> > The fastest way is going to be array_values():
> >
> > http://www.php.net/array_values
> >
> > --Larry Garfield
> >
> >
> > On 8/31/10 10:43 AM, Tontonq Tontonq wrote:
> >
> >> a quick question
> >> lets say i have an array like that
> >>
> >>
> >> Array
> >> (
> >> [300] => 300
> >> [301] => 301
> >> [302] => 302
> >> [303] => 303
> >> [304] => 304
> >> [305] => 305
> >> [306] => 306
> >> [307] => 307
> >> [308] => 308
> >> ...
> >> how can i change keys to 0,1,2,3,.. by faster way
> >> (it should like that)>
> >> Array
> >> (
> >> [0] => 300
> >> [1] => 301
> >> [2] => 302
> >> [3] => 303
> >> ....
> >>
> >>
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
I'd use a loop for something like that:
$new_array = array('0-300'=>0, '301-400'=>0, '401-500'=>0, '501+'=>0);
foreach($old_array as $a)
{
switch(true)
{
case $a <= 300:
{
$new_array['0-300']++;
break;
}
case $a <= 400:
{
$new_array['301-400']++;
break;
}
case $a <= 500:
{
$new_array['401-500']++;
break;
}
default:
{
$new_array['501+']++;
break;
}
}
}
Thanks,
Ash
http://www.ashleysheridan.co.uk