ID:               39456
 Updated by:       [EMAIL PROTECTED]
 Reported By:      ricardo dot matters at mindbench dot nl
-Status:           Open
+Status:           Feedback
 Bug Type:         Arrays related
 Operating System: debian cur 2.6.18-1-686-bigmem
 PHP Version:      5.2.0
 New Comment:

Please provide less complicated example. 
If there is a problem with array_multisort(), I believe you should be
able to reproduce it with direct call.


Previous Comments:
------------------------------------------------------------------------

[2006-11-10 09:36:48] ricardo dot matters at mindbench dot nl

Description:
------------
To sort an multidimensional array, I'm using a wrapper for
array_multisort. Was working just fine, but as from 5.2, nothing is
being sorted. Documentation lacks any information if array_multisort
has been changed.

Reproduce code:
---------------
function multisort() {
  $n = func_num_args();
  $ar = func_get_arg($n-1);
  if (!is_array($ar))
    return false;

  for ($i = 0; $i < $n-1; $i++) {
    $col[$i] = func_get_arg($i);
  }

  foreach($ar as $key => $val) {
    foreach($col as $kkey => $vval) {
      if (is_string($vval)) {
        ${"subar$kkey"}[$key] = $val[$vval];
      }
    }
  }

  foreach($col as $key => $val) {
    $arv[] = (is_string($val) ? ${"subar$key"} : $val);
  }
  $arv[] = $ar;

  call_user_func_array("array_multisort", $arv);
  return $ar;
}

$ar = array(
  array('id' => 1, 'weight' => 78, 'ts' => 123456),
  array('id' => 1, 'weight' => 78, 'ts' => 123457),
  array('id' => 1, 'weight' => 98, 'ts' => 134526),
  array('id' => 1, 'weight' => 10, 'ts' => 112456),
  array('id' => 1, 'weight' => 56, 'ts' => 177776)
);
print_r(multisort('weight', SORT_DESC, SORT_NUMERIC, 'ts', SORT_DESC,
SORT_NUMERIC, $ar));

Expected result:
----------------
Array
(
    [0] => Array
        (
            [id] => 1
            [weight] => 98
            [ts] => 134526
        )
    [1] => Array
        (
            [id] => 1
            [weight] => 78
            [ts] => 123457
        )
    [2] => Array
        (
            [id] => 1
            [weight] => 78
            [ts] => 123456
        )
    [3] => Array
        (
            [id] => 1
            [weight] => 56
            [ts] => 177776
        )
    [4] => Array
        (
            [id] => 1
            [weight] => 10
            [ts] => 112456
        )

)


Actual result:
--------------
Array
(
    [0] => Array
        (
            [id] => 1
            [weight] => 78
            [ts] => 123456
        )

    [1] => Array
        (
            [id] => 1
            [weight] => 78
            [ts] => 123457
        )

    [2] => Array
        (
            [id] => 1
            [weight] => 98
            [ts] => 134526
        )

    [3] => Array
        (
            [id] => 1
            [weight] => 10
            [ts] => 112456
        )

    [4] => Array
        (
            [id] => 1
            [weight] => 56
            [ts] => 177776
        )

)



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=39456&edit=1

Reply via email to