Access array element indexed by numerical string

前端 未结 4 1316
有刺的猬
有刺的猬 2020-12-30 04:52

I have encountered something odd.

I have a php array, indexed with numerical keys. However it appears impossible to access any of the elements because php automatica

4条回答
  •  -上瘾入骨i
    2020-12-30 05:07

    foreach ($array as $key => $value){
        var_dump($key);
        var_dump($value);
    }
    

    shows

    string(1) "1"
    string(3) "one"
    

    But echo $array['"1"']; gives

    E_NOTICE :  type 8 -- Undefined index: "1" -- at line 8
    

    That's strange!

提交回复
热议问题