Forum Moderators: coopster

Message Too Old, No Replies

Group Entries in an Array

and reindexing.

         

inveni0

6:30 pm on Apr 8, 2009 (gmt 0)

10+ Year Member



Is there a short cut for grouping similar items in an array, yet having it rewrite the keys for the array, as well?

For instance, I have an array like this:


$array[0] = "Orange";
$array[1] = "Orange";
$array[2] = "Orange";
$array[3] = "Ball";
$array[4] = "Ball";

I've been using array_unique to group like fields, but that gives me something like this:


$array[0] = "Orange";
$array[3] = "Ball";

But I need it to read:


$array[0] = "Orange";
$array[1] = "Ball";

Any ideas? I've been reading through lots of PHP documentation on array functions, but I must be missing something. I tried using 'sort', but that doesn't work at all. It just outputs a standard variable as "1";

Thanks for any ideas!

inveni0

6:45 pm on Apr 8, 2009 (gmt 0)

10+ Year Member



NEVERMIND! I'm an idiot. I was misusing sort by writing: $array = sort($array); so I was getting that "1" or "true" value returned by sort. DUH.