as we know if we dont ptovide the key in array by default it uses 0
and n + 1 for keys
example
$arr = array("raashid" , "aslam", "bhatt");
it is same as
$arr = array (0 ="raashid", 1 =>............ , 2 =>....);
and another example
$arr = array("raashid" , 2 ="aslam", "bhatt");
0 2 3
the value raashid will automatically get value 0
while as aslam stays at 2 (note we can rearrange them using
array_vaules() function)
bhatt will automatically get 3 because as i stated early n + 1 for
keys
that was just an intro my main point is
$arr = array("raashid" , "2" ="aslam", "bhatt");
here the key("2") is a string and it must not use n + 1
bhatt's key should be 1 as 0 + 1 = 1
now
var_dump($arr);
array(3) { [0]= string(7) "raashid" [2]= string(5) "aslam" [3]=>
string(5) "bhatt" }
see the key for raashid is converted into integer but it was not
and bhatt gets key 3 thst is previous + 1
and n + 1 for keys
example
$arr = array("raashid" , "aslam", "bhatt");
it is same as
$arr = array (0 ="raashid", 1 =>............ , 2 =>....);
and another example
$arr = array("raashid" , 2 ="aslam", "bhatt");
0 2 3
the value raashid will automatically get value 0
while as aslam stays at 2 (note we can rearrange them using
array_vaules() function)
bhatt will automatically get 3 because as i stated early n + 1 for
keys
that was just an intro my main point is
$arr = array("raashid" , "2" ="aslam", "bhatt");
here the key("2") is a string and it must not use n + 1
bhatt's key should be 1 as 0 + 1 = 1
now
var_dump($arr);
array(3) { [0]= string(7) "raashid" [2]= string(5) "aslam" [3]=>
string(5) "bhatt" }
see the key for raashid is converted into integer but it was not
and bhatt gets key 3 thst is previous + 1
Comment