添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

PHP Utils: 复制/批量移除 数组内元素

Categories: PHP ; Tagged with: ; @ September 9th, 2010 22:20

1. 将$source内的元素复制到$target数组内
2. 将$target数组内 拥有与 $source相同key的元素移除.

* 将指定Array内的元素复制到目标Array中, 如果具有相同key, 则会被覆盖. public static function copyArrayItems($source, $target) { foreach($source as $sourceItemKey=>$sourceItemValue) { $target[$sourceItemKey] = $sourceItemValue; return $target; * 移除$target数组中中带有 $source中元素相同key的元素. * @param $source * @param $target * @return unknown_type public static function removeArrayItems($source, $target) { foreach($source as $sourceKey => $sourseValue) { unset($target[$sourseValue]); return $target;

有关数组的操作: http://liguoliang.com/2010/php-array-简单操作小结/