title: check if value from a foreach loop is in an array
body: <p>Ok I'm seriously stuck, I've been working on a nav menu that I just cannot get to function how I want it to so i've changed tack but am now stuck again so any help would be much appreciated and desperately needed!</p>
  
  <p>I have the code below and am trying to do the following - I have an array that holds info for all the pages of a site and then another array that holds the ids of the pages that are child pages. What I want to do is use a foreach loop to loop through all the pages of the first array and check whether their ids are in the array of child ids or not. If they are not then they are top level nav pages and I want to output some code and then set up another foreach loop which will check whether any subpages have a parent id of the current page and so on.</p>
  
  <p>I can't seem to work out how to compare $b with the ids in the $childpages array no matter what I try! Is this even possible and if so how please?</p>
  
  <p>This is the first section of what im trying at present</p>
  
  <pre><code>&lt;?php function buildMenu4 ($allpages, $childpages) {
  
      foreach ($allpages as $pages){
  
      $a = $pages['parentid'];
      $b = $pages['id'];
      $c = $childpages;
  
  
      echo "&lt;ul&gt;\n";
  
  
  
          if (!in_array($b, $c)) {
  
          DO SOMETHING..........
  </code></pre>
  
  <p>Array contents of $c:</p>
  
  <pre><code>Array 
  ( 
  [0] =&gt; Array ( [id] =&gt; 6 ) 
  [1] =&gt; Array ( [id] =&gt; 15 ) 
  [2] =&gt; Array ( [id] =&gt; 100 ) 
  [3] =&gt; Array ( [id] =&gt; 101 ) 
  [4] =&gt; Array ( [id] =&gt; 103 ) 
  [5] =&gt; Array ( [id] =&gt; 104 ) 
  [6] =&gt; Array ( [id] =&gt; 105 ) 
  )
  </code></pre>
  
  <p>edit ---------------------------------</p>
  
  <p>I have reworked my code and am back to a variation of where I was a couple of days ago!! Anyway the code below works as intended until I try to loop it and then it just echoes the results of the first foreach loop e.g. foreach ($allpages as $pages){..... but fails to do anything else.</p>
  
  <p>I am trying to make a function called loopMenu and then run this recursively until there are no more pages to be displayed. I have tried to write the function as shown with the pusedo code in the code block below but I just can't get it to work. I may have muddled up some of the arguments or parameters or perhaps I have just made a big mistake somewhere but I can't see it - any help would be hugely appreciated and desperately needed!</p>
  
  <pre><code> &lt;?php function buildMenu6 ($allpages, $childpageids, $childpages, $subchildpages) {
  
  
          foreach ($childpageids as $childid){
              $c[] = $childid['id'];
  
              };
  
  
              echo "&lt;ul&gt;\n";  
  
          foreach ($allpages as $pages){
  
  
          $a = $pages['parentid'];
          $b = $pages['id'];
  
  
              if (!in_array($b, $c)){
  
                  echo "&lt;li&gt;&lt;a href=" . $pages['url'] . "&gt;" . $pages['linklabel'] . "&lt;/a&gt;";
  
  
                      WHERE I WANT THE FUNCTION TO START E.G. function loopMenu($childpages, $subchildpages){...the code that follows....
  
  
                      echo"&lt;ul&gt;\n";
  
                      foreach ($childpages as $childparent) {
  
                              $d = $childparent['parentid'];
                              $e = $childparent['id'];
  
  
  
                              if (($d == $b) or ($d == $g)) {
  
                                  echo "&lt;li&gt;&lt;a href=" . $childparent['url'] . "&gt;" . $childparent['linklabel'] . "&lt;/a&gt;";
                                      echo "&lt;ul&gt;\n";
  
                                      foreach ($subchildpages as $subchild){
                                          $g = $subchild['id'];
                                          $f = $subchild['parentid'];
  
  
                                          if ($f == $e){
  
                                              echo "&lt;li&gt;&lt;a href=" . $subchild['url'] . "&gt;" . $subchild['linklabel'] . "&lt;/a&gt;";
                          WHERE I TRY TO RERUN THE FUNCTION USING loopMenu($childparent, $subchild);                  
                                              echo "&lt;li/&gt;";
                                              };
                                          };
  
                                      echo"&lt;/ul&gt;\n";
                                  echo "&lt;/li&gt;";
  
                          };
                      };
                      echo "&lt;/ul&gt;\n";
  
  
  WHERE I WANT MY FUNCTION TO END E.G. };
  
  
  echo "&lt;/li&gt;";
  
                  };
  
  
      };
          echo "&lt;/ul&gt;\n";
          }; ?&gt;
  </code></pre>
  
  <p>Then I call the main buildMenu6 function like so:</p>
  
  <pre><code>&lt;?php buildMenu6($pageids, $childPageIds, $childPageArray, $childPageArray); ?&gt;
  </code></pre>