如果我这样做了:
<?php
$array = array();
$array['bar'] = "bar";
$array['foo'] = array();
?>
如何在$ array ['foo']数组中添加值? (但不喜欢将另一个数组添加到只有键和值中)
答案 0 :(得分:4)
$array['foo']['blah'] = 'asdf';
答案 1 :(得分:2)
<?php
$array = array();
$array['bar'] = 'bar';
$array['foo'] = array();
$array['foo']['key'] = 'var'; // if you want it to be hash table
or
$array['foo'][] = 'var'; // generates the index for you.
?>
然后,如果你想访问那件事:
<?php echo $array['foo']['key']; ?>
或者如果您使用[]方式:
<?php echo $array['foo'][0]; ?>
答案 2 :(得分:0)
$array['foo']['x'] = 'something';
答案 3 :(得分:0)
$array['foo'][] = $your_value_to_insert;
答案 4 :(得分:0)
喜欢@cyclone和:
$array['foo'] = array("foo" => "bar", 12 => true);
答案 5 :(得分:0)
您可以这样做:
$array['foo'] = array('id' => 1, 'name' => 'abc');