title: PHP - Get values from Array
body: <p>I am trying to retrieve a value from an Array. Here is the code:</p>
  
  <pre><code>$opt=get_records_sql($sql1);
  
  print_object($opt);
  
  $n = count($opt);
  if (empty($opt)){
      echo 'No options selected';
  }
  else{
      $optno = $opt["subjectid"];
      echo '&lt;br&gt;$optno = '.$optno;
  }
  </code></pre>
  
  <p>I tried to use: <code>$opt["subjectid"]</code> but I get the following error:</p>
  
  <pre><code>Notice: Undefined index: subjectid
  </code></pre>
  
  <p>Contents of array:</p>
  
  <pre><code>Array
  (
      [1] =&gt; stdClass Object
          (
              [uname] =&gt; JHollands06
              [tutor] =&gt; M LSt
              [subjectid] =&gt; 1
              [year] =&gt; 2010
              [optid] =&gt; 1
          )
  
  )
  </code></pre>
  
  <p>How to I fetch the data subjectid which has value 1?</p>