title: Sort array by value
body: <p>I am creating a "Pinned" feature for my forum and I am looking for a way to put my pinned topics at the beginning of the array so that they are "stuck" to the top of the page.</p>
  
  <p>If the topic is not pinned then <code>topic_pinned=NULL</code> if it is pinned then <code>topic_pinned=0</code>.</p>
  
  <p>The array is sorted by <code>topic_updated</code>. The pinned topics need to stay sorted by <code>topic_updated</code> while staying at the top of the page, and then under the pinned topics are the non-pinned topics, which are also sorted by <code>topic_updated</code>.</p>
  
  <p>Topic Array (<code>$forum_topic_results</code>):</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [topic_id] =&gt; 4
              [topic_subject] =&gt; Test Subject #4
              [topic_date] =&gt; 2015-09-10 18:34:18
              [topic_by] =&gt; 1
              [topic_pinned] =&gt; 
              [topic_updated] =&gt; 2015-09-10 20:37:22
          )
  
      [1] =&gt; Array
          (
              [topic_id] =&gt; 3
              [topic_subject] =&gt; Test Subject #3
              [topic_date] =&gt; 2015-08-22 09:24:40
              [topic_by] =&gt; 1
              [topic_pinned] =&gt; 0
              [topic_updated] =&gt; 2015-09-04 22:02:31
          )
  
      [2] =&gt; Array
          (
              [topic_id] =&gt; 2
              [topic_subject] =&gt; Test Subject #2
              [topic_date] =&gt; 2015-08-15 10:56:00
              [topic_by] =&gt; 1
              [topic_pinned] =&gt; 
              [topic_updated] =&gt; 2015-09-04 19:45:32
          )
  
      [3] =&gt; Array
          (
              [topic_id] =&gt; 1
              [topic_subject] =&gt; Test Subject #1
              [topic_date] =&gt; 2015-08-30 19:48:17
              [topic_by] =&gt; 1
              [topic_pinned] =&gt; 0
              [topic_updated] =&gt; 2015-09-03 00:44:38
          )
  )
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>/**
   * getAllTopics
   *
   * Retreives the topics of the chosen category from the `forum_topics` table.
   *
   * @param   $cat_id
   * @access  public
   */
  public function getAllTopics($cat_id=NULL)
  {
      $database=$this-&gt;database;
  
      $database-&gt;query('SELECT topic_id, topic_subject, topic_date, topic_by, topic_pinned, topic_locked FROM forum_topics WHERE topic_cat = :catid ORDER BY topic_updated DESC', array(':catid' =&gt; $cat_id));
      $result = $database-&gt;statement-&gt;fetchAll(PDO::FETCH_ASSOC);
  
      return $result;
  }
  
  # Get topics
  $forum_topic_results = $this-&gt;getAllTopics($_GET['cat']);
  foreach($forum_topic_results as $forum_topic_row)
  {
      # Get user's username.
      $topic_by=SearchUser($forum_topic_row['topic_by']);
  
      $data.='&lt;tr&gt;'.
          '&lt;td&gt;'.
              '&lt;h3&gt;&lt;a href="'.$_SERVER['PHP_SELF'].'?action=forum_posts&amp;topic='.$forum_topic_row['topic_id'].'"&gt;'.$forum_topic_row['topic_subject'].'&lt;/a&gt;&lt;/h3&gt;'.
              'by '.$topic_by['username'].' on '.date('D M d, Y g:i a', strtotime($forum_topic_row['topic_date'])).
          '&lt;/td&gt;'.
      '&lt;/tr&gt;';
  }
  </code></pre>
  
  <p>Outcome I want:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [topic_id] =&gt; 3
              [topic_subject] =&gt; Test Subject #3
              [topic_date] =&gt; 2015-08-22 09:24:40
              [topic_by] =&gt; 1
              [topic_pinned] =&gt; 0
              [topic_updated] =&gt; 2015-09-04 22:02:31
          )
  
      [1] =&gt; Array
          (
              [topic_id] =&gt; 1
              [topic_subject] =&gt; Test Subject #1
              [topic_date] =&gt; 2015-08-30 19:48:17
              [topic_by] =&gt; 1
              [topic_pinned] =&gt; 0
              [topic_updated] =&gt; 2015-09-03 00:44:38
          )
  
      [2] =&gt; Array
          (
              [topic_id] =&gt; 4
              [topic_subject] =&gt; Test Subject #4
              [topic_date] =&gt; 2015-09-10 18:34:18
              [topic_by] =&gt; 1
              [topic_pinned] =&gt; 
              [topic_updated] =&gt; 2015-09-10 20:37:22
          )
  
      [3] =&gt; Array
          (
              [topic_id] =&gt; 2
              [topic_subject] =&gt; Test Subject #2
              [topic_date] =&gt; 2015-08-15 10:56:00
              [topic_by] =&gt; 1
              [topic_pinned] =&gt; 
              [topic_updated] =&gt; 2015-09-04 19:45:32
          )
  )
  </code></pre>