0

I am trying to sort a multidimensional array by multiple values but I keep getting the error:

Warning: array_multisort() [function.array-multisort]: Array sizes are inconsistent in -- on line 19

Line 19 is where I call the array_multisort function:

array_multisort($column1, $column2, $column3, $row);

I have been unable to replicate the issue in a test, so I haven't had much luck in solving the issue.

So basically I am saving a MySql table as a multidimensional associative array. Then I am trying to sort the rows by three different columns. I have checked and all of the arrays passed into the array_multisort() function are the same size. I checked both by manually looking through every row and by using sizeof().

Any ideas what could be causing this and/or what the solution is?

2 Answers 2

7

to answer your original question, this normally happens with an uninitiated variable. For example:

foreach ($arr_this_referers as $int_key => $arr_row) {
    $arr_vol[$int_key]  = $arr_row['int_cnt'];
}

will cause WARNING due to uninitiated variable $arr_vol but initialize variable before the for loop:

$arr_vol = array();
foreach ($arr_this_referers as $int_key => $arr_row) {
    $arr_vol[$int_key]  = $arr_row['int_cnt'];
}
array_multisort($arr_vol, SORT_DESC, $arr_this_referers);

... & warning disappears, hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

1

I ended just using uasort() instead. it gave me no problems at all and it was pretty straight forward to set up the cmp logic.

Still no idea what the issue with array_multisort() was.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.