使用array_multisort

时间:2012-08-14 02:58:48

标签: php mysql sorting

我在查询数据库后在脚本开头使用array_multisort。工作良好。数组已排序。

稍后在同一个脚本中,我在对数据库进行另一次查询后再次使用array_multisort。对于第二次调用,数组的长度相同,但长度与最初使用的数组的长度不同。

我在error_log中收到“array_multisort数组大小不一致”警告。数组是否会从一次调用持续到下一次调用,从而导致此错误?如果是这样,有没有办法清理函数并删除第二次调用之前使用的初始数组?

以下是包含var_dump输出的代码的摘要视图:

...1st query...

...1st array_multisort use based on the query...
array_multisort($shiftdate, $beg24, $uniquename, $subunit, $unit, $dept, $shiftdetail, $scheduledStaff);

...1st var_dump values based on array_multisort...
array(3) {
  [0]=>
  array(10) {
    ["uniquename"]=>
    string(3) "Bob"
    ["shiftdate"]=>
    string(10) "2012-08-12"
    ["subunit"]=>
    string(1) "1"
    ["unit"]=>
    string(1) "1"
    ["dept"]=>
    string(1) "1"
    ["shiftdetail"]=>
    string(5) "7a-3p"
    ["firstname"]=>
    string(0) ""
    ["lastname"]=>
    string(0) ""
    ["email"]=>
    string(0) ""
    ["beg24"]=>
    string(4) "7.00"
  }
  [1]=>
  array(10) {
    ["uniquename"]=>
    string(4) "Cara"
    ["shiftdate"]=>
    string(10) "2012-08-12"
    ["subunit"]=>
    string(1) "1"
    ["unit"]=>
    string(1) "1"
    ["dept"]=>
    string(1) "1"
    ["shiftdetail"]=>
    string(5) "7a-3p"
    ["firstname"]=>
    string(0) ""
    ["lastname"]=>
    string(0) ""
    ["email"]=>
    string(0) ""
    ["beg24"]=>
    string(4) "7.00"
  }
  [2]=>
  array(10) {
    ["uniquename"]=>
    string(4) "Ryan"
    ["shiftdate"]=>
    string(10) "2012-08-12"
    ["subunit"]=>
    string(1) "1"
    ["unit"]=>
    string(1) "1"
    ["dept"]=>
    string(1) "1"
    ["shiftdetail"]=>
    string(5) "7a-3p"
    ["firstname"]=>
    string(0) ""
    ["lastname"]=>
    string(0) ""
    ["email"]=>
    string(0) ""
    ["beg24"]=>
    string(4) "7.00"
  }
}


...2nd query...

...2nd array_multisort use based on the query...
array_multisort($shiftdate, $beg24, $uniquename, $subunit, $unit, $dept, $shiftdetail, $firstname, $lastname, $email, $scheduledStaffAndThoseWithDetail);

...NOTE: error_log warning occurs at this second array_multisort use...PHP Warning:  array_multisort() [<a href='function.array-multisort'>function.array-multisort</a>]: Array sizes are inconsistent...

...2nd var_dump values based on array_multisort...
array(2) {
  [0]=>
  array(10) {
    ["uniquename"]=>
    string(4) "Ryan"
    ["shiftdate"]=>
    string(10) "2012-08-12"
    ["subunit"]=>
    string(1) "1"
    ["unit"]=>
    string(1) "1"
    ["dept"]=>
    string(1) "1"
    ["shiftdetail"]=>
    string(5) "7a-3p"
    ["firstname"]=>
    string(4) "Ryan"
    ["lastname"]=>
    string(5) "Dobbs"
    ["email"]=>
    string(17) "dobbsr@gmail.com"
    ["beg24"]=>
    string(4) "7.00"
  }
  [1]=>
  array(10) {
    ["uniquename"]=>
    string(4) "Cara"
    ["shiftdate"]=>
    string(10) "2012-08-12"
    ["subunit"]=>
    string(1) "1"
    ["unit"]=>
    string(1) "1"
    ["dept"]=>
    string(1) "1"
    ["shiftdetail"]=>
    string(5) "7a-3p"
    ["firstname"]=>
    string(4) "Cara"
    ["lastname"]=>
    string(6) "Smith"
    ["email"]=>
    string(14) "cara@gmail.com"
    ["beg24"]=>
    string(4) "7.00"
  }
}

0 个答案:

没有答案