doubo1871 2015-01-03 12:08
浏览 68

警告:来自多维数组的非法字符串偏移

In the code below, I am trying to use echo $r_id[$d_id]['name'];" where $r_id = china and $d_id = china1 was defined in a previous page, so as to replicate echo $china['china1']['name'];, which will give me the value of Beef and Broccoli from the array.

<?php
$china = array(
'china1'=> array(
'cat'=> "Chinese",
'id'=>"C1",
'name'=>"Beef and Broccoli",
'instruction'=> "Placeholder")
);

if(isset($_GET["r_id"])){
        if(isset($_GET["d_id"])){
            $r_id = $_GET["r_id"];
            $d_id = $_GET["d_id"];
        }
    }

    echo $r_id[$d_id]['name'];

?>

But all I am getting is this:

Warning: Illegal string offset 'china1' in....

Warning: Illegal string offset 'name' in....

Where did I get it wrong? Code for the previous page:

        <table border = 1px align = center style = "margin-top:100px;">
        <tr>
            <td><a href="recipes.php?r_id=china&d_id=china1"><img src="images/china1icon.jpg"/></a></td>
            <td><img src="images/vietnam1icon.jpg"/></td>
            <td><img src ="images/japan1icon.jpg"/></td>
            <td><img src ="images/korea1icon.jpg"/></td>
        </tr>
    </table>
  • 写回答

1条回答 默认 最新

  • douchun5969 2015-01-03 12:27
    关注

    You cannot pass a variable directly into the URL: <a href="recipes.php?r_id=$china&d_id=china1"></a>. You should print out the variable in the URL like <a href="recipes.php?r_id=" . $china . "&d_id=china1"></a>, and then it'd work.

    And on this page, $r_id is now 'china', if you want echo $r_id[$d_id]['name']; to become echo $china['china1']['name'];, then you need to do $$r_id[$d_id]['name'], note the double dollar sign, which defines a variable variable.

    评论

报告相同问题?

悬赏问题

  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答