PHP - 我无法创建关联数组
PHP - I can't make assoc array
我有这个代码:
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 -->
当然,它不起作用。
解析错误:
syntax error, unexpected '"home"' (T_CONSTANT_ENCAPSED_STRING), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in D:\xampp\htdocs\index.php on line 11`
如何修复?
只需使用 "aaa"=>"bbb" 而不是 "aaa"->"bbb" 和 =
我有这个代码:
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 -->
当然,它不起作用。
解析错误:
syntax error, unexpected '"home"' (T_CONSTANT_ENCAPSED_STRING), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in D:\xampp\htdocs\index.php on line 11`
如何修复?
只需使用 "aaa"=>"bbb" 而不是 "aaa"->"bbb" 和 =