【问题标题】:PHP - I can't make assoc arrayPHP - 我无法制作 assoc 数组
【发布时间】:2017-05-30 16:46:48
【问题描述】:

我有这个代码:

menu.php

<?php
$menu = [
    [
        "id"->"home",
        "name"->"Home page",
        "url"->"/index.php"
    ]
}; ?>

index.php

<?php
require 'menu.php';
$menubar = [
    "menu" -> $menu,
    "current" -> "home" // this line
]; ?>
<!-- and some html -->

当然,它不起作用。

解析错误:

语法错误,意外的 '"home"' (T_CONSTANT_ENCAPSED_STRING),在第 11 行的 D:\xampp\htdocs\index.php 中需要标识符 (T_STRING) 或变量 (T_VARIABLE) 或 '{' 或 '$'`

如何修复?

【问题讨论】:

    标签: php associative-array


    【解决方案1】:

    只需使用 "aaa"=>"bbb" 代替 "aaa"->"bbb" 和 =

    http://php.net/manual/en/language.types.array.php

    【讨论】:

    • 哇,没想到这么简单;)
    猜你喜欢
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多