0

これまでのところ、removeAllValuesMatching と呼ばれるこの関数を PHP で作成しましたが、機能していないようです。$arr と $value の 2 つのパラメーターを渡します。なぜこれが起こっているのか分かりません。どんな助けでも大歓迎です。これは私がこれまでに持っているものです:

<?php 
$arr = array(
   'a' => "one",
   'b' => "two",
   'c' => "three",
   'd' => "two",
   'e' => "four",
   'f' => "five",
   'g' => "three",
   'h' => "two"
);
function removeAllValuesMatching($arr, $value){
 foreach ($arr as $key => $value){
 if ($arr[$key] == $value){
 unset($arr[$key]);
 }
 }
 return $arr = array_values($arr);
 }

print_r(removeAllValuesMatching($arr, "two"));

?>
4

2 に答える 2