Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.