请选择 进入手机版 | 继续访问电脑版
绿茶科技社区

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
使用传递的数组递归替换第一个数组的元素 array_replace_recursive
  1. $base = array('citrus' => array( "orange") , 'berries' => array("blackberry", "raspberry"), );

  2. $replacements = array('citrus' => array('pineapple'), 'berries' => array('blueberry'));

  3. $basket = array_replace_recursive($base, $replacements);
复制代码

带索引检查计算数组的交集,用回调函数比较索引 array_intersect_uassoc
  1. $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");

  2. $array2 = array("a" => "GREEN", "B" => "brown", "yellow", "red");

  3. print_r(array_intersect_uassoc($array1, $array2, "strcasecmp"));
复制代码

递归地合并一个或多个数组 array_merge_recursive
  1. $ar1 = array("color" => array("favorite" => "red"), 5);\

  2. $ar2 = array(10, "color" => array("favorite" => "green", "blue"));\

  3. $result = array_merge_recursive($ar1, $ar2);
复制代码

使用传递的数组递归替换第一个数组的元素 array_replace_recursive
  1. $base = array('citrus' => array( "orange") , 'berries' => array("blackberry", "raspberry"), );

  2. $replacements = array('citrus' => array('pineapple'), 'berries' => array('blueberry'));

  3. $basket = array_replace_recursive($base, $replacements);

  4. print_r($basket);\
复制代码
将一个线性数组转换为一个树,或者多维数组
  1. function array_stack (&$a, $p = '@parent', $c = '@children')

  2.     {

  3.       $l = $t = array();

  4.       foreach ($a AS $key => $val):

  5.         if (!$val[$p]) $t[$key] =& $l[$key];

  6.         else $l[$val[$p]][$c][$key] =& $l[$key];

  7.         $l[$key] = (array)$l[$key] + $val;

  8.       endforeach;

  9.       return $a = array('tree' => $t, 'leaf' => $l);

  10.     }

  11.     $node = array();

  12.     $node[1] = array('@parent' => 0, 'title' => 'I am node 1.');

  13.     $node[2] = array('@parent' => 1, 'title' => 'I am node 2.');

  14.     $node[3] = array('@parent' => 2, 'title' => 'I am node 3.');

  15.     $node[4] = array('@parent' => 1, 'title' => 'I am node 4.');

  16.     $node[5] = array('@parent' => 4, 'title' => 'I am node 5.');

  17.     print_r(array_stack($node));
复制代码


分享到 :
0 人收藏

2 个回复

倒序浏览
李永京  高级会员 | 2019-11-15 03:08:34
我擦!我要沙发!
老翅寒暑  金牌会员 | 2019-11-29 11:52:28

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

举报|Archiver|手机版|小黑屋|Lvchakeji Inc.  

Powered by Discuz! X3.3 © 2001-2016 Comsenz Inc.

返回顶部