[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'
);