Jump to content

problem with usort


php1

Recommended Posts

dear all,

I have a usort function to sort an array based on one value in the array

 

usort($split1, 'callback');

print_r($split1);

function callback($a, $b)

 

{

 

 

if ($a[$key] == $b[$key]) return 0;

 

  return $a[3] > $b[3] ? 1 : -1; 

 

}

 

my $split1 is given below:

Array (

[0] => Array ( [0] => 22-08-2008 [1] => 18:12:20 [2] => 101 [3] => 120 )

[1] => Array ( [0] => 22-08-2008 [1] => 20:01:15 [2] => 190 [3] => 120 )

[2] => Array ( [0] => 22-08-2008 [1] => 20:01:15 [2] => 190 [3] => 220 )

)

here  sorting works fine

$split1[0][3]=$split1[1][3]= 120 . so each time i print the $split1 i got the $split[0] and $split[1] interchanged. is there any way to keep the array index same if the values are identical

Link to comment
https://forums.phpfreaks.com/topic/126258-problem-with-usort/
Share on other sites

I am displaying each of this values in a table. so my

table row1 =  22-08-2008,18:12:20,101,120

table row2 =  22-08-2008,20:01:15,190,120

table row3 =  22-08-2008,20:01:15,190,220

 

i got the table like the above for the ffirst time. if i click refresh then my row became

 

table row1 =  22-08-2008,20:01:15,190,120

table row2 =  22-08-2008,18:12:20,101,120

table row3 =  22-08-2008,20:01:15,190,220

 

ie table row1 and table row2 got interchanged.

is there any way to keep the table row1 as it is using usort

Link to comment
https://forums.phpfreaks.com/topic/126258-problem-with-usort/#findComment-653596
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.