title: Sort PHP array base on its value
body: <p>When I did </p>
  
  <pre><code>$result = array_count_values(Visitor::all()-&gt;pluck('device')-&gt;toArray());
  $result = asort($result,SORT_NATURAL);
  return $result;
  </code></pre>
  
  <p>I kept getting </p>
  
  <blockquote>
    <p>The Response content must be a string or object implementing __toString(), "boolean" given.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/DSlIO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DSlIO.png" alt="enter image description here"></a></p>
  
  <p>This is an array </p>
  
  <pre><code>array_count_values(Visitor::all()-&gt;pluck('device')-&gt;toArray())
  </code></pre>
  
  <p>It returns</p>
  
  <pre><code>{
      iPhone: 202,
      Windows NT 6.1: 2428,
      Windows NT 10.0: 2588,
      Macintosh: 1397,
      iPad: 12,
      Windows NT 6.2: 50,
      Windows NT 6.3: 90,
      X11: 442,
      compatible: 1813,
      Windows NT 5.1: 97,
      Linux: 227,
      Windows: 86,
      TweetmemeBot/4.0: 8,
      ) { :: 14,
      Windows NT 6.0: 7,
      User-Agent,Mozilla/5.0 : 1,
      KHTML, like Gecko: 6,
      Unknown: 11,
      Android: 1,
      Android 7.1.1: 1,
      Android 7.1.2: 2,
      Windows NT x.y: 2,
      Windows NT 6.1) AppleWebKit/537.36 : 7,
      Windows NT 5.0: 1,
      Windows NT 8.0: 1,
      web crawler :: robots.txt exclude elefent: 1,
      Windows NT: 1,
      Linux 4.4.0-116-generic: 1
  }
  </code></pre>
  
  <p>I want to sort them in a desc base on <code>values</code>. </p>
  
  <p>Please help </p>