title: Searching for a value in an array using PHP
body: <p>I have a list of users in my mongodb database, which can then follow each other -pretty standard. Using php I want to check if a specific user is following another user. My data looks like this.</p>
  
  <pre><code>array (
    '_id' =&gt; ObjectId("56759157e1095db549d63af1"),
    'username' =&gt; 'Joe',
    'following' =&gt; 
    array (
      0 =&gt; 
      array (
        'username' =&gt; 'John',
      ),
      1 =&gt; 
      array (
        'username' =&gt; 'Tom',
      ),
    ),
  )
  array (
        '_id' =&gt; ObjectId("56759132e1095de042d63af4"),
        'username' =&gt; 'Tom',
        'following' =&gt; 
        array (
          0 =&gt; 
          array (
            'username' =&gt; 'Joe',
          ),
          1 =&gt; 
          array (
            'username' =&gt; 'John',
          ),
          2 =&gt; 
          array (
            'username' =&gt; 'Sam',
          ),
        ),
      )
  </code></pre>
  
  <p>I want a query that will check if Joe is following Sam (which he's not) - so it would produce no results. However, if I was to query the database to check if Tom was following Sam, then it would produce a result to indicate he is (because he is). Do you know how I would do this in PHP? I've experimented with Foreach loops, but I haven't been able to get the results I want.</p>