Wol*_*'08 2 php arrays indexing multidimensional-array array-key
$products = array(
'paper' => "Paper Section" => array
(
'copier' => "Copier and Multipurpose",
'inkjet' => "Inkjet Printer",
),
'pens' => "Pen Section" => array
(
'ball' => "Ballpoint Pens",
'hilite' => "Highlighters"
),
'misc' => "Miscellaneous Section" => array
(
'tape' => "Sticky Tape",
'glue' => "Adhesive"
)
);
echo "<pre>";
foreach ($products as $section => $items)
foreach ($items as $key => $value)
echo "$section:\t$key\t($value)<br />";
echo "</pre>";
Run Code Online (Sandbox Code Playgroud)
显然我在这里要做的是为$ section集分配索引,并且我在尝试这样做时遇到错误.有没有其他方法可以做到这一点,还是在PHP中是不可能的?
$products = array(
'paper' => array(
'title' => "Paper Section",
'copier' => "Copier and Multipurpose",
'inkjet' => "Inkjet Printer"
)
);
Run Code Online (Sandbox Code Playgroud)
比如上面的东西.另一个选择是添加另一个维度:
$products = array(
'paper' => array(
'meta' => array(
'title' => "Paper Section"
),
'data' => array(
'copier' => "Copier and Multipurpose",
'inkjet' => "Inkjet Printer"
)
)
);
Run Code Online (Sandbox Code Playgroud)