PHP 数组删除元素

// 删除数组内特定元素
 function array_delete ($needle, $haystack, $all = true) {
     $haystack_updated = $haystack;
     foreach ($haystack as $num => $val) {
         if ($val == $needle && $all) {
             unset ($haystack_updated [$num]);
         }
         elseif ($val == $needle && $all === false && !isset ($done)) {
             $done = true;
             unset ($haystack_updated [$num]);
         }
     }
     $haystack_updated = array_values ($haystack_updated);
     return $haystack_updated;
 }

你可能感兴趣的:(PHP,数组删除元素)