dounan9070 2015-05-21 12:07
浏览 160
已采纳

如何在PHP中正确声明/定义关联数组?

I wrote a program to define an associative array titled $aFilter and tried to print it but I'm not able to. I tried two ways to achieve this but couldn't succeed. Following are the two ways I tried.

Way 1:

<!DOCTYPE html>
<html>
<body>

<?php
$aFilter = Array
        (
            ['pages'] => 1,
            ['photo'] => 1,
            ['link'] => 1,
            ['event'] => 1,
            ['friend'] => 1,
            ['user_status'] => 1,
            ['poll'] => 1,
            ['quiz'] => 1,
            ['market'] => 1,
            ['apps'] => 1
        )
        print_r($aFilter);
?>

</body>
</html>

Way 2:

<!DOCTYPE html>
<html>
<body>

<?php
$aFilter = Array
        (
            ['pages'] => 1
            ['photo'] => 1
            ['link'] => 1
            ['event'] => 1
            ['friend'] => 1
            ['user_status'] => 1
            ['poll'] => 1
            ['quiz'] => 1
            ['market'] => 1
            ['apps'] => 1
        )
        print_r($aFilter);
?>

</body>
</html>

After executing both of the above codes I'm getting blank white screen. No any error or warning. Why so happens? How can I get errors and warnings displayed on my webpage without making any change to php.ini file settings?

Can someone please correct the mistake I'm making and help me?

  • 写回答

3条回答 默认 最新

  • doukun8944 2015-05-21 12:08
    关注

    You forgot an ; after defining the array. And also don't use [] when defining an array. More info on array's.

    $aFilter = Array(
                'pages' => 1,
                'photo' => 1,
                'link' => 1,
                'event' => 1,
                'friend' => 1,
                'user_status' => 1,
                'poll' => 1,
                'quiz' => 1,
                'market' => 1,
                'apps' => 1
            );
            print_r($aFilter);
    

    print_r() displays information about a variable in a way that's readable by humans. It is not the code you need to write.

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

报告相同问题?

悬赏问题

  • ¥15 Python程序,深度学习,有偿私
  • ¥15 扫描枪扫条形码出现问题
  • ¥15 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开