title: Access array by string key x, where x is "123"
body: <p>We have an array of which the keys are Strings, but those strings sometimes just are numbers (e.g. "123"). When trying to access the array by the key "123", we get an Undefined Index notice. When accessing it by just the integer 123, we get the Undefined Offset notice. This tells us we're trying to index it correctly using the "123" string, but it's still not set.</p>
  
  <p>Trying to come up with an example for this SO question this is hard, since PHP converts array keys in our test case to integers automatically, while in our real-world application this does not happen (due to use of a Java Bridge). The test array we're trying now is:</p>
  
  <pre><code>&lt;?php
  $array = array("123" =&gt; array(108, 8));
  var_dump($array);
  ?&gt;
  </code></pre>
  
  <p>This returns:</p>
  
  <pre><code>array(1) { [123]=&gt; array(2) { [0]=&gt; int(108) [1]=&gt; int(8) } }
  </code></pre>
  
  <p>While in our real-world equivalent, it would return:</p>
  
  <pre><code>array(1) { ["123"]=&gt; array(2) { [0]=&gt; int(108) [1]=&gt; int(8) } }
  </code></pre>
  
  <p>So in the real world the index actually is a String:</p>
  
  <pre><code>&lt;?php
  var_dump(array_keys($array));
  ?&gt;
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>array(1) { [0]=&gt; string(3) "123" }
  </code></pre>
  
  <p>So, finally the question is the output of the following code:</p>
  
  <pre><code>&lt;?php
  foreach ($array as $key =&gt; $value) {
      if (!isset($array[$key])) {
          print "What is happening here?";
      }
  } 
  ?&gt;
  </code></pre>
  
  <p>which gives:</p>
  
  <pre><code>What is happening here?
  </code></pre>
  
  <p>Based on Yoshi's comment, here's working test code:</p>
  
  <pre><code>&lt;?php
  $array = (array)json_decode('{"123":[108,8]}');
  foreach ($array as $key =&gt; $value) {
      if (!isset($array[$key])) {
          print "What is happening here?";
      } else {
          print "Nothing to see here, move along";
      }
  } 
  ?&gt;
  </code></pre>