$ wrap数组是一个包装数据和选项数组。如何回显调用$ wrap数组变量的$ options或$ data的数组值?
$wrap = array($data, $options);
$data = array(1,2,3,4,5,6,7,8);
$options = array('a', 'b', "key" => "c", 'd', 'e');
答案 0 :(得分:1)
$wrap = array($data, $options);
相当于$wrap = array(0=>$data, 1=>$options);
即通过$wrap[1]
获得与$ option相同的数组,因此$ option ['key'] => $包[1] [ '钥匙']
E.g。
<?php
$data = array(1,2,3,4,5,6,7,8);
$options = array('a', 'b', "key" => "c", 'd', 'e');
$wrap = array($data, $options);
echo $wrap[1]['key'];
但您可能希望为$ wrap使用关联索引来提高可读性
<?php
$data = array(1,2,3,4,5,6,7,8);
$options = array('a', 'b', "key" => "c", 'd', 'e');
$wrap = array('data'=>$data, 'opts'=>$options);
echo $wrap['opts']['key'];
答案 1 :(得分:0)
echo $wrap[0][0]; //outputs 1
echo $wrap[1]['key']; //outputs c
极其有用的阅读:http://php.net/types.array