From c0d39a476438a80bac8c25dfb2203932f20d630b Mon Sep 17 00:00:00 2001 From: Damien Seguy Date: Mon, 28 May 2001 17:50:50 +0000 Subject: [PATCH] Made the array_splice example compliant cut/paste. Added an (obvious?) detail to array_diff(). git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@48774 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/array.xml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/functions/array.xml b/functions/array.xml index 76fd1dc67a..c37bea3127 100644 --- a/functions/array.xml +++ b/functions/array.xml @@ -184,15 +184,16 @@ array_count_values ($array); // returns array (1=>2, "hello"=>2, "world"=& <function>Array_diff</function> example -$array1 = array ("a" => "green", "red", "blue"); +$array1 = array ("a" => "green", "red", "blue", "red"); $array2 = array ("b" => "green", "yellow", "red"); $result = array_diff ($array1, $array2); - This makes $result have array - ("blue"); + This makes $result have + array ("blue");. Multiple occurences in + $array1 are all treated the same way. See also array_intersect. @@ -1295,14 +1296,21 @@ $a[$x] = $y array_splice ($input, $x, 1, $y) <function>Array_splice</function> examples $input = array ("red", "green", "blue", "yellow"); +array_splice ($input, 2); +// $input is now array ("red", "green") -array_splice ($input, 2); // $input is now array ("red", "green") -array_splice ($input, 1, -1); // $input is now array ("red", "yellow") +$input = array ("red", "green", "blue", "yellow"); +array_splice ($input, 1, -1); +// $input is now array ("red", "yellow") + +$input = array ("red", "green", "blue", "yellow"); array_splice ($input, 1, count($input), "orange"); - // $input is now array ("red", "orange") +// $input is now array ("red", "orange") + +$input = array ("red", "green", "blue", "yellow"); array_splice ($input, -1, 1, array("black", "maroon")); - // $input is now array ("red", "green", - // "blue", "black", "maroon") +// $input is now array ("red", "green", +// "blue", "black", "maroon")