>I've read the manual several times on sorting multi-dimensional arrays,
>but I can't seem to wrap my mind around what I need to do to accomplish
>my goal.
>
>//this is what I'm doing: (stepping through a result set, and putting it
>into a multi-dimensional array.
>
>while ($row = mysql_fetch_array
Ooops, forgot to specify the compare function with usort(); all working now.
Phil.
-Original Message-
From: Phil Ewington - 43 Plc [mailto:[EMAIL PROTECTED]
Sent: 22 December 2003 14:08
To: [EMAIL PROTECTED]
Subject: [PHP] sorting multi-dimensional arrays
Hi All,
I am trying to sort a
Sweet! Thanks for the help!
-Original Message-
From: Martin Towell [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 01, 2002 7:15 PM
To: 'Bloom, Chris'; '[EMAIL PROTECTED]'
Subject: RE: [PHP] Sorting Multi-Dimensional Arrays using uksort()
try using usort() inst
try using usort() instead of uksort() - (i haven't checked the manual but) I
believe uksort is for sorting based on the keys and not the values, which is
what you're trying to do
-Original Message-
From: Bloom, Chris [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 02, 2002 9:57 AM
To: '[E
it was just a typo... I meant:
$categories[0]["id"]=2;
$categories[0]["name"]="lele";
$categories[1]["id"]=6;
$categories[1]["name"]="lala";
.. ...
and so on...
At 00:52 16/9/2001 -0400, you wrote:
>The below code would result in an array of:
>
>$categories[0]["id"]=2;
>$categories[0]["name"]=
The easiest way is probably to just use a for loop.
For instance (no pun intended...well, maybe just a little one):
$imax = sizeof($joke);
for ($i = 0; $i < $imax; $i++)
{
if (sizeof($joke[$i]) > 1)
{
sort($joke[$i]);
}
}
That will handle the sorting of any two-dimensional
hh, no, maybe the samplecode I posted it's not your case, sorry...
> I have a question about sorting multidimensional arrays. Here is my
problem:
>
> I have an 2-d array:
> $joke[1][rating]=10;
> $joke[2][rating]=20;
> $joke[3][rating]=15;
>
>
> I would like to sort the jokes into an
Try this (it should work):
while(list($k, $v) = each($myarray)){
$myarray[$k] = (int) $v;
}
arsort($myarray);
reset($myarray);
while(list($k, $v) = each($myarray)){
echo $k, ' == ', $v, "\n;
}
For better comprehension look at this post:
>Hey guys..
>
>I have this array that looks like thi
8 matches
Mail list logo