Warning: array_multisort () [function.array-multisort]: argument # 1 expected as an array or sort flag in

the following code throws an error in the header. I tried to do this, but all I had were pages that got the same error (not an explanation). This is not a problem as it actually works and canceling the error with @ works great. Although I'm still wondering why I couldn't execute array_multisort just once without getting this error.

public function getMostRelevant(){

  list($occurrences, $keywords) = $this->occurr_keyw_array;


  array_multisort($occurrences, SORT_DESC, SORT_NUMERIC,
      $keywords);

  $return_array = array(
         array($occurrences[0], $keywords[0]),
         array($occurrences[1], $keywords[1]),
         array($occurrences[2], $keywords[2])
         );

  return $return_array;

 }

      

+2


a source to share


3 answers


You can check before a function to check if it is an array. For instance:

if(is_array($occurrences)){ 
     array_multisort($occurrences, SORT_DESC, SORT_NUMERIC,$keywords);
}

      



I think this will help you.

+1


a source


Make sure to $this->occurr_keyw_array

and then $occurrences

contain what you expect from them.



0


a source


You can try to declare the arrays you are using in advance:

$occurrences = array();

      

It doesn't make much sense to me, but it worked here. I suppose this is another PHP Quirk.

0


a source







All Articles