drus39136 2010-03-02 19:37
浏览 50
已采纳

来自密钥的数组调用无法正常工作

I'm trying to call to a specific part of an array with the key # and it's not working. I can output the array and see it...

Array
(
    [6] => Array
        (
            [0] => user@domain.com
            [1] => user@domain.com
        )

    [7] => Array
        (
            [0] => user@domain.com
            [1] => user@domain.com
        )

    [8] => Array
        (
            [0] => user@domain.com
            [1] => user@domain.com
        )

)

This array is $emailDB. I can call to the array manually with $emailDB[7] and it works, but if my call is dynamic like this it won't work...

<?php
$value = 7;
print_r($emailDB[$value]);
?>

I've never had an issue like this with an array so it's very odd. What really sucks is I'm under deadline with a form not working on a client's site...joy.

We tried this with no luck...

<?php
$value = 7;
print_r($emailDB[intval($value)]);
?>

I thought intval() would assist but it did not.

  • 写回答

3条回答 默认 最新

  • dongxili9934 2010-03-02 21:01
    关注

    You're post implies a bug in php itself, which I highly doubt. What's more likely is that what you posted doesn't properly represent the code you're running.

    Why don't try this. Make a brand new empty php file. Hardcode the array keys and values and assign them to the $emailDB variable, and then try

    $value = 7;
    print_r($emailDB[$value]);
    

    You will see you don't have the problem that you claim. You have now started the debugging process, and now you can look at the working, and non working code to compare the difference.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序