 <p>Not very elegant solution too, but also works and do not require recreating array. Also, you can access the element value.</p> <pre><code>$array = (array)json_decode('{"123":100}'); $array_keys = array_keys($array); $array = (object)$array; foreach ($array_keys as $key) { if (!isset($array-&gt;$key)) { print "What is happening here?"; } else { print "It's OK val is {$array-&gt;$key}"; } } </code></pre> <p>Note <code>$</code> before key in <code>$array-&gt;$key</code>, it is important.</p>