您好,登錄后才能下訂單哦!
有哪些特別的數(shù)組方法?針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
使用傳遞的數(shù)組遞歸替換第一個(gè)數(shù)組的元素 array_replace_recursive
$base = array('citrus' => array( "orange") , 'berries' => array("blackberry", "raspberry"), ); $replacements = array('citrus' => array('pineapple'), 'berries' => array('blueberry')); $basket = array_replace_recursive($base, $replacements);
帶索引檢查計(jì)算數(shù)組的交集,用回調(diào)函數(shù)比較索引 array_intersect_uassoc
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "GREEN", "B" => "brown", "yellow", "red"); print_r(array_intersect_uassoc($array1, $array2, "strcasecmp"));
遞歸地合并一個(gè)或多個(gè)數(shù)組 array_merge_recursive
$ar1 = array("color" => array("favorite" => "red"), 5);\ $ar2 = array(10, "color" => array("favorite" => "green", "blue"));\ $result = array_merge_recursive($ar1, $ar2);
使用傳遞的數(shù)組遞歸替換第一個(gè)數(shù)組的元素 array_replace_recursive
$base = array('citrus' => array( "orange") , 'berries' => array("blackberry", "raspberry"), ); $replacements = array('citrus' => array('pineapple'), 'berries' => array('blueberry')); $basket = array_replace_recursive($base, $replacements); print_r($basket);\
將一個(gè)線性數(shù)組轉(zhuǎn)換為一個(gè)樹(shù),或者多維數(shù)組
function array_stack (&$a, $p = '@parent', $c = '@children') { $l = $t = array(); foreach ($a AS $key => $val): if (!$val[$p]) $t[$key] =& $l[$key]; else $l[$val[$p]][$c][$key] =& $l[$key]; $l[$key] = (array)$l[$key] + $val; endforeach; return $a = array('tree' => $t, 'leaf' => $l); } $node = array(); $node[1] = array('@parent' => 0, 'title' => 'I am node 1.'); $node[2] = array('@parent' => 1, 'title' => 'I am node 2.'); $node[3] = array('@parent' => 2, 'title' => 'I am node 3.'); $node[4] = array('@parent' => 1, 'title' => 'I am node 4.'); $node[5] = array('@parent' => 4, 'title' => 'I am node 5.'); print_r(array_stack($node));
關(guān)于有哪些特別的數(shù)組方法問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。