Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 543 Bytes

pull.md

File metadata and controls

23 lines (17 loc) · 543 Bytes
标题 标签
pull(过滤数组) array,beginner(数组,初学者)

改变原始数组以过滤掉指定的值。

  • 使用 array_values() 和 array_diff() 从 $items 中删除指定的值。

代码如下:

function pull(&$items,...$values){
  $items = array_values(array_diff($items,$values));
  return $items;
}

使用方式:

$items = ['a', 'b', 'c', 'a', 'b', 'c'];
pull($items, 'a', 'c'); // $items 将是 ['b', 'b']