title: PHP getting a specific key value at a specfic index in an array
body: <p>I've looked a bunch on here, and I've seem some similar type of questions, but none of them seemed to work in my situation (or at least I couldn't make them work), so hopefully this isn't an exact repeat.</p>
  
  <p>I built an array that looks as follows:</p>
  
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [article_id] =&gt; 1
          [article_title] =&gt; Article 1
          [article_content] =&gt; This is some dummy text for the first article.
      )
  
  [1] =&gt; Array
      (
          [article_id] =&gt; 2
          [article_title] =&gt; Article 2
          [article_content] =&gt; This is the content for article #2
      )
  )
  </code></pre>
  
  <p>So the array has 3 keys (article_id, article_title, article_content), and what I'm trying to do is get a specific value at a specific index.</p>
  
  <p>So, for example, if the page url is </p>
  
  <pre><code>/article.php?id=1
  </code></pre>
  
  <p>I first assign the id to a variable:</p>
  
  <pre><code>$linkID = $_GET['id'];
  </code></pre>
  
  <p>and now I want to search the array to find an article id match (to the $LinkID variable):</p>
  
  <pre><code>$foundAtPos = array_search($linkID, array_column($datas, 'article_id'));
  </code></pre>
  
  <p>this works fine, and gives me a matching "index" position, which is a great start, and now I want to assign the other two key values to variables (or echo them to the screen, something to show me that I've retrieved the correct id - article_title value). </p>
  
  <p>This is the part where I get really stuck.  I can easily display all values from the array, but I'm not looking to do that. I want to get ONLY the specific values that match the corresponding article_id.</p>
  
  <p>Here's a few things I've tried (unsuccessfully):</p>
  
  <pre><code>    foreach ($datas as $keyName) {
          echo $keyName['article_title'];
      }
  </code></pre>
  
  <p>This gives me all the article titles, but that's not what I'm aiming for.</p>
  
  <p>This bit I got from another stack overflow post, and it seemed like it was close, but I couldn't adapt it correctly.</p>
  
  <pre><code> foreach($datas as $firstKey =&gt; $firstValue) {
    echo array_keys($firstValue, $firstValue['article_title'])[0].': '.$firstValue['article_title'].'&lt;/br&gt;';
  }
  </code></pre>
  
  <p>Same problem, gives me all the data, not just the row I'm trying to retrieve.</p>
  
  <p>So I've gone in circles for hours, and it seems like this should be a common thing, but it's eluding me at the moment, so I'd appreciate any suggestions you fine folks might have.</p>
  
  <p>Here's my entire function, for reference.</p>
  
  <pre><code>if (isset($_GET['id'])) {
      $linkID = $_GET['id'];
  
      foreach ($datas as $keyName) {
          //echo $keyName['article_title'];
      }
  
     //foreach($datas as $firstKey =&gt; $firstValue) {
    //echo array_keys($firstValue, $firstValue['article_title'])[0].': '.$firstValue['article_title'].'&lt;/br&gt;';
  //}
  
      //retrieve index of match in array
      $foundAtPos = array_search($linkID, array_column($datas, 'article_id'));
  
      print_r($datas[$foundAtPos]);
  
  
  } else {
      header('Location: index.php');
      exit();
  }
  </code></pre>
  
  <p>thanks!</p>