Note that there are some explanatory texts on larger screens.

plurals
  1. POAre PHP Integer array Indexes really numeric?
    primarykey
    data
    text
    <p>Consider this example</p> <pre><code>&lt;?php $test = array("00"=&gt;"A","B","C","D","E"); print_r($test); echo "&lt;br&gt;"; echo $test[0]; echo "&lt;br&gt;"; echo $test["0"]; echo "&lt;br&gt;"; echo $test["00"]; echo "&lt;br&gt;"; echo $test[00]; ?&gt; </code></pre> <p>Output</p> <blockquote> <p>Array ( [00] => A [0] => B [1] => C [2] => D [3] => E ) </p> <p>B</p> <p>B</p> <p>A</p> <p>B</p> </blockquote> <p><strong>Q1.</strong> Why is <code>$test[0]</code> same as <code>$test["0"]</code> whereas <code>$test[00]</code> is not same as <code>$test["00"]</code> </p> <p><strong>Q2.</strong> If the answer to <strong>Q1</strong> is that because <code>00 = 0</code> numerically then why does this array have one index as <code>00</code> and another as <code>0</code>?</p> <p><strong>Q3.</strong> If you cannot access <code>$test["00"]</code> using <code>$test[0]</code> then how do you know which index is numeric and which is string? if both are only numbers</p> <p><strong>Edit</strong></p> <p>Based on the answers so far, there is another question in my mind. Here goes Question 4.</p> <p><strong>Q4.</strong> Why is <code>if(00==0)</code> true and <code>if(07==7)</code> false? ( for array indexes)</p> <p><strong>Q5.</strong> </p> <pre><code>$test = array("00"=&gt;"A","0"=&gt;"B","000"=&gt;"C","0000"=&gt;"D","00000"=&gt;"E"); echo $test[0]; </code></pre> <p>Why the output is <strong>B</strong>, should it not be <strong>A</strong> ? because that is the first element in the array, at 0th position</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload