我试图删除数组中以 [1] 开头的所有项目的完整级别
我对数组一点运气都没有。对我来说有点新。阅读我发现的所有东西都不清楚,也不清楚我的例子。
继承人我的代码到目前为止。我可以删除提交。但我不能再进一步了,而且我不知道如何在标题、特殊、项目等中删除所有这些作为项目 [1] - 常规凯撒沙拉
感谢您提供的任何帮助
code
<?php
// version:
$testarray =
Array(
"heading" => Array
(
"0" => 'Salads',
"1" => 'Salads',
"2" => 'Pasta',
),
"special" => Array
(
"0" => '',
"1" => '',
"2" => '',
),
"item" => Array
(
"0" => 'Small Green',
"1" => 'Regular Caesar',
"2" => 'Baked Lasagna',
),
"description" => Array
(
"0" => 'Grape tomatoes, onions, green peppers and cucumbers on the bed of crisp lettuce.',
"1" => 'Classic recipe with romaine lettuce and croutons',
"2" => 'With meat sauce, tomato vegetarian sauce or Alfredo sauce',
),
"price" => Array
(
"0" => 'See Desc',
"1" => '$5.99',
"2" => '$9.69',
),
"notes" => Array
(
"0" => 'Available in Small ($2.99), Regular ($5.99)',
"1" => '',
"2" => '',
),
"submit_val" => 'Submit'
);
echo "testarray";
echo "<pre>";
print_r($testarray);
echo "</pre>";
echo "<hr>";
$removed_data=removeItem($testarray,'Submit');
echo "removed_data";
echo "<pre>";
print_r($removed_data);
echo "</pre>";
echo "<hr>";
die();
// works for submit
function removeItem($look_in_Array, $remove){
foreach($look_in_Array as $key => $value) {
echo $key . ' = ' . $value . '<br>';
if ($value ==$remove) {
echo 'found '.$remove."<br>";
unset($look_in_Array[$key]);
}
}
return $look_in_Array;
}
?>
想要的输出?:
sample of desired output
$testarray =
Array(
"heading" => Array
(
"0" => 'Salads',
"1" => 'Pasta',
),
"special" => Array
(
"0" => '',
"1" => '',
),
"item" => Array
(
"0" => 'Small Green',
"1" => 'Baked Lasagna',
),
"description" => Array
(
"0" => 'Grape tomatoes, onions, green peppers and cucumbers on the bed of crisp lettuce.',
"1" => 'With meat sauce, tomato vegetarian sauce or Alfredo sauce',
),
"price" => Array
(
"0" => 'See Desc',
"1" => '$9.69',
),
"notes" => Array
(
"0" => 'Available in Small ($2.99), Regular ($5.99)',
"1" => '',
),
"submit_val" => 'Submit'
);