我有这个数组:
$array = array(
"foo" => "bar",
"barw" => "21",
"bara" => "22",
"barq" => "25",
"multix" => array(
"1" => array(
"ar1" => "food",
"ar2" => "dr",
"ar3" => "ch",
"ar4" => "ju"
),
"2" => array(
"ar1" => "food",
"ar2" => "dr",
"ar3" => "ch",
"ar4" => "ju"
),
"893" => "bar",
"563" => "bar",
"hd8" => "bar",
"multiv" => array(
"1" => array(
"ar1" => "food",
"ar2" => "dr",
"ar3" => "ch",
"ar4" => "ju"
),
"2" => array(
"ar1" => "food",
"ar2" => "dr",
"ar3" => "ch",
"ar4" => "ju"
),
"tw" => "bar",
"qa" => "bar",
"op" => "bar"
)
)
);
我正在阅读和写作:
echo '<pre>';
print_r($array);
echo '</pre>';
echo "<br/>";
echo $array['multix']['1']['ar1'].'<br/>';
echo "<br/>";
echo $array['multix']['1']['ar2'].'<br/>';
echo "<br/>";
echo $array['multix']['1']['ar3'].'<br/>';
echo "<br/>";
echo $array['multix']['1']['ar4'].'<br/>';
$array['multix']['1']['ar4'] = "lego";
但是,我无法删除我选择的数组,如:
unset($array['multiv']['1']);
echo '<pre>';
print_r($array);
echo '</pre>';
如何使用密钥删除数组?
答案 0 :(得分:3)
您的multiv
数组位于multix
数组中,因此您需要添加multix
名称
unset($array['multix']['multiv']['1']);
如果multiv
应该是索引级别的一个,那么你可能会错误地设置你的数组。