Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in

15,693

You can apply a check before the function to check if it's an array. For example:

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

I think this would help you.

Share:
15,693
johnny
Author by

johnny

Updated on June 05, 2022

Comments

  • johnny
    johnny almost 2 years

    the following code produces the error in the title. I've tried to google it, but all I got were pages who got the same error (and not an explanation thereof). This isn't really a problem since it's actually working and cancelling the error out with the @ works out just fine. Though I'm still wondering why I haven't been able to 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;
    
     }
    
  • johnny
    johnny about 14 years
    this is $this->occurr_keyw_array: Array ( [0] => Array ( [0] => 5 [1] => 0 [2] => 0 [3] => 0 [4] => 99 ) [1] => Array ( [0] => lung [1] => is [2] => most [3] => important [4] => organ ) )
  • Kamil Szot
    Kamil Szot about 14 years
    does $occurences really contain Array ( [0] => 5 [1] => 0 [2] => 0 [3] => 0 [4] => 99 ) after list($occurren.... line?