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