mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
applying PEAR coding standards on examples
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@138081 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
d9784b8655
commit
23396d4d4e
45 changed files with 238 additions and 233 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- $Revision: 1.4 $ -->
|
||||
<refentry id="function.array-combine">
|
||||
<refnamediv>
|
||||
<refname>array_combine</refname>
|
||||
|
@ -29,8 +29,8 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$a = array('green','red','yellow');
|
||||
$b = array('avocado','apple','banana');
|
||||
$a = array('green', 'red', 'yellow');
|
||||
$b = array('avocado', 'apple', 'banana');
|
||||
$c = array_combine($a, $b);
|
||||
|
||||
print_r($c);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.array-count-values">
|
||||
<refnamediv>
|
||||
|
@ -23,8 +23,8 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$array = array (1, "hello", 1, "world", "hello");
|
||||
print_r(array_count_values ($array));
|
||||
$array = array(1, "hello", 1, "world", "hello");
|
||||
print_r(array_count_values($array));
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.14 -->
|
||||
<refentry id="function.array-diff-assoc">
|
||||
<refnamediv>
|
||||
|
@ -27,9 +27,9 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$array1 = array ("a" => "green", "b" => "brown", "c" => "blue", "red");
|
||||
$array2 = array ("a" => "green", "yellow", "red");
|
||||
$result = array_diff_assoc ($array1, $array2);
|
||||
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
|
||||
$array2 = array("a" => "green", "yellow", "red");
|
||||
$result = array_diff_assoc($array1, $array2);
|
||||
|
||||
/* The result is:
|
||||
Array
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.14 -->
|
||||
<refentry id="function.array-diff">
|
||||
<refnamediv>
|
||||
|
@ -26,9 +26,9 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$array1 = array ("a" => "green", "red", "blue", "red");
|
||||
$array2 = array ("b" => "green", "yellow", "red");
|
||||
$result = array_diff ($array1, $array2);
|
||||
$array1 = array("a" => "green", "red", "blue", "red");
|
||||
$array2 = array("b" => "green", "yellow", "red");
|
||||
$result = array_diff($array1, $array2);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<!-- $Revision: 1.12 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.62 -->
|
||||
<refentry id="function.array-filter">
|
||||
<refnamediv>
|
||||
|
@ -30,15 +30,15 @@
|
|||
<![CDATA[
|
||||
<?php
|
||||
function odd($var) {
|
||||
return ($var % 2 == 1);
|
||||
return($var % 2 == 1);
|
||||
}
|
||||
|
||||
function even($var) {
|
||||
return ($var % 2 == 0);
|
||||
return($var % 2 == 0);
|
||||
}
|
||||
|
||||
$array1 = array ("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5);
|
||||
$array2 = array (6, 7, 8, 9, 10, 11, 12);
|
||||
$array1 = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5);
|
||||
$array2 = array(6, 7, 8, 9, 10, 11, 12);
|
||||
|
||||
echo "Odd :\n";
|
||||
print_r(array_filter($array1, "odd"));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.107 -->
|
||||
<refentry id="function.array-flip">
|
||||
<refnamediv>
|
||||
|
@ -38,8 +38,8 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$trans = array_flip ($trans);
|
||||
$original = strtr ($str, $trans);
|
||||
$trans = array_flip($trans);
|
||||
$original = strtr($str, $trans);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -51,8 +51,8 @@ $original = strtr ($str, $trans);
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$trans = array ("a" => 1, "b" => 1, "c" => 2);
|
||||
$trans = array_flip ($trans);
|
||||
$trans = array("a" => 1, "b" => 1, "c" => 2);
|
||||
$trans = array_flip($trans);
|
||||
print_r($trans);
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<refentry id="function.array-intersect-assoc">
|
||||
<refnamediv>
|
||||
<refname>array_intersect_assoc</refname>
|
||||
|
@ -25,9 +25,9 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$array1 = array ("a" => "green", "b" => "brown", "c" => "blue", "red");
|
||||
$array2 = array ("a" => "green", "yellow", "red");
|
||||
$result_array = array_intersect_assoc ($array1, $array2);
|
||||
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
|
||||
$array2 = array("a" => "green", "yellow", "red");
|
||||
$result_array = array_intersect_assoc($array1, $array2);
|
||||
|
||||
/* $result_array will look like:
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.14 -->
|
||||
<refentry id="function.array-intersect">
|
||||
<refnamediv>
|
||||
|
@ -26,9 +26,9 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$array1 = array ("a" => "green", "red", "blue");
|
||||
$array2 = array ("b" => "green", "yellow", "red");
|
||||
$result = array_intersect ($array1, $array2);
|
||||
$array1 = array("a" => "green", "red", "blue");
|
||||
$array2 = array("b" => "green", "yellow", "red");
|
||||
$result = array_intersect($array1, $array2);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.array-keys">
|
||||
<refnamediv>
|
||||
|
@ -30,15 +30,15 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$array = array (0 => 100, "color" => "red");
|
||||
print_r(array_keys ($array));
|
||||
$array = array(0 => 100, "color" => "red");
|
||||
print_r(array_keys($array));
|
||||
|
||||
$array = array ("blue", "red", "green", "blue", "blue");
|
||||
print_r(array_keys ($array, "blue"));
|
||||
$array = array("blue", "red", "green", "blue", "blue");
|
||||
print_r(array_keys($array, "blue"));
|
||||
|
||||
$array = array ("color" => array("blue", "red", "green"),
|
||||
"size" => array("small", "medium", "large"));
|
||||
print_r(array_keys ($array));
|
||||
$array = array("color" => array("blue", "red", "green"),
|
||||
"size" => array("small", "medium", "large"));
|
||||
print_r(array_keys($array));
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.62 -->
|
||||
<refentry id="function.array-map">
|
||||
<refnamediv>
|
||||
|
@ -32,7 +32,7 @@
|
|||
<![CDATA[
|
||||
<?php
|
||||
function cube($n) {
|
||||
return $n*$n*$n;
|
||||
return($n * $n * $n);
|
||||
}
|
||||
|
||||
$a = array(1, 2, 3, 4, 5);
|
||||
|
@ -65,11 +65,11 @@ Array
|
|||
<![CDATA[
|
||||
<?php
|
||||
function show_Spanish($n, $m) {
|
||||
return "The number $n is called $m in Spanish";
|
||||
return("The number $n is called $m in Spanish");
|
||||
}
|
||||
|
||||
function map_Spanish($n, $m) {
|
||||
return array ($n => $m);
|
||||
return(array($n => $m));
|
||||
}
|
||||
|
||||
$a = array(1, 2, 3, 4, 5);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.12 -->
|
||||
<refentry id="function.array-merge-recursive">
|
||||
<refnamediv>
|
||||
|
@ -33,9 +33,9 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$ar1 = array ("color" => array ("favorite" => "red"), 5);
|
||||
$ar2 = array (10, "color" => array ("favorite" => "green", "blue"));
|
||||
$result = array_merge_recursive ($ar1, $ar2);
|
||||
$ar1 = array("color" => array("favorite" => "red"), 5);
|
||||
$ar2 = array(10, "color" => array("favorite" => "green", "blue"));
|
||||
$result = array_merge_recursive($ar1, $ar2);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.array-merge">
|
||||
<refnamediv>
|
||||
|
@ -32,9 +32,9 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$array1 = array ("color" => "red", 2, 4);
|
||||
$array2 = array ("a", "b", "color" => "green", "shape" => "trapezoid", 4);
|
||||
$result = array_merge ($array1, $array2);
|
||||
$array1 = array("color" => "red", 2, 4);
|
||||
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
|
||||
$result = array_merge($array1, $array2);
|
||||
print_r($result);
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.11 -->
|
||||
<refentry id="function.array-multisort">
|
||||
<refnamediv>
|
||||
|
@ -73,9 +73,9 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$ar1 = array ("10", 100, 100, "a");
|
||||
$ar2 = array (1, 3, "2", 1);
|
||||
array_multisort ($ar1, $ar2);
|
||||
$ar1 = array("10", 100, 100, "a");
|
||||
$ar2 = array(1, 3, "2", 1);
|
||||
array_multisort($ar1, $ar2);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -93,9 +93,9 @@ array_multisort ($ar1, $ar2);
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$ar = array (array ("10", 100, 100, "a"), array (1, 3, "2", 1));
|
||||
array_multisort ($ar[0], SORT_ASC, SORT_STRING,
|
||||
$ar[1], SORT_NUMERIC, SORT_DESC);
|
||||
$ar = array(array("10", 100, 100, "a"), array(1, 3, "2", 1));
|
||||
array_multisort($ar[0], SORT_ASC, SORT_STRING,
|
||||
$ar[1], SORT_NUMERIC, SORT_DESC);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.array-pad">
|
||||
<refnamediv>
|
||||
|
@ -33,15 +33,15 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$input = array (12, 10, 9);
|
||||
$input = array(12, 10, 9);
|
||||
|
||||
$result = array_pad ($input, 5, 0);
|
||||
// result is array (12, 10, 9, 0, 0)
|
||||
$result = array_pad($input, 5, 0);
|
||||
// result is array(12, 10, 9, 0, 0)
|
||||
|
||||
$result = array_pad ($input, -7, -1);
|
||||
// result is array (-1, -1, -1, -1, 12, 10, 9)
|
||||
$result = array_pad($input, -7, -1);
|
||||
// result is array(-1, -1, -1, -1, 12, 10, 9)
|
||||
|
||||
$result = array_pad ($input, 2, "noop");
|
||||
$result = array_pad($input, 2, "noop");
|
||||
// not padded
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.array-pop">
|
||||
<refnamediv>
|
||||
|
@ -28,8 +28,8 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$stack = array ("orange", "banana", "apple", "raspberry");
|
||||
$fruit = array_pop ($stack);
|
||||
$stack = array("orange", "banana", "apple", "raspberry");
|
||||
$fruit = array_pop($stack);
|
||||
print_r($stack);
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.array-push">
|
||||
<refnamediv>
|
||||
|
@ -40,8 +40,8 @@ $array[] = $var;
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$stack = array ("orange", "banana");
|
||||
array_push ($stack, "apple", "raspberry");
|
||||
$stack = array("orange", "banana");
|
||||
array_push($stack, "apple", "raspberry");
|
||||
print_r($stack);
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.13 -->
|
||||
<refentry id="function.array-rand">
|
||||
<refnamediv>
|
||||
|
@ -37,11 +37,11 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
srand ((float) microtime() * 10000000);
|
||||
$input = array ("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
|
||||
$rand_keys = array_rand ($input, 2);
|
||||
print $input[$rand_keys[0]]."\n";
|
||||
print $input[$rand_keys[1]]."\n";
|
||||
srand((float) microtime() * 10000000);
|
||||
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
|
||||
$rand_keys = array_rand($input, 2);
|
||||
print $input[$rand_keys[0]] . "\n";
|
||||
print $input[$rand_keys[1]] . "\n";
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.62 -->
|
||||
<refentry id="function.array-reverse">
|
||||
<refnamediv>
|
||||
|
@ -27,9 +27,9 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$input = array ("php", 4.0, array ("green", "red"));
|
||||
$result = array_reverse ($input);
|
||||
$result_keyed = array_reverse ($input, TRUE);
|
||||
$input = array("php", 4.0, array("green", "red"));
|
||||
$result = array_reverse($input);
|
||||
$result_keyed = array_reverse($input, TRUE);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.array-shift">
|
||||
<refnamediv>
|
||||
|
@ -30,8 +30,8 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$stack = array ("orange", "banana", "apple", "raspberry");
|
||||
$fruit = array_shift ($stack);
|
||||
$stack = array("orange", "banana", "apple", "raspberry");
|
||||
$fruit = array_shift($stack);
|
||||
print_r($stack);
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.array-slice">
|
||||
<refnamediv>
|
||||
|
@ -50,10 +50,10 @@
|
|||
<?php
|
||||
$input = array ("a", "b", "c", "d", "e");
|
||||
|
||||
$output = array_slice ($input, 2); // returns "c", "d", and "e"
|
||||
$output = array_slice ($input, 2, -1); // returns "c", "d"
|
||||
$output = array_slice ($input, -2, 1); // returns "d"
|
||||
$output = array_slice ($input, 0, 3); // returns "a", "b", and "c"
|
||||
$output = array_slice($input, 2); // returns "c", "d", and "e"
|
||||
$output = array_slice($input, 2, -1); // returns "c", "d"
|
||||
$output = array_slice($input, -2, 1); // returns "d"
|
||||
$output = array_slice($input, 0, 3); // returns "a", "b", and "c"
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.14 -->
|
||||
<refentry id="function.array-splice">
|
||||
<refnamediv>
|
||||
|
@ -118,26 +118,26 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$input = array ("red", "green", "blue", "yellow");
|
||||
array_splice ($input, 2);
|
||||
// $input is now array ("red", "green")
|
||||
$input = array("red", "green", "blue", "yellow");
|
||||
array_splice($input, 2);
|
||||
// $input is now array("red", "green")
|
||||
|
||||
$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, -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 = array("red", "green", "blue", "yellow");
|
||||
array_splice($input, 1, count($input), "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",
|
||||
$input = array("red", "green", "blue", "yellow");
|
||||
array_splice($input, -1, 1, array("black", "maroon"));
|
||||
// $input is now array("red", "green",
|
||||
// "blue", "black", "maroon")
|
||||
|
||||
$input = array ("red", "green", "blue", "yellow");
|
||||
array_splice ($input, 3, 0, "purple");
|
||||
// $input is now array ("red", "green",
|
||||
$input = array("red", "green", "blue", "yellow");
|
||||
array_splice($input, 3, 0, "purple");
|
||||
// $input is now array("red", "green",
|
||||
// "blue", "purple", "yellow");
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<!-- $Revision: 1.12 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.array-unique">
|
||||
<refnamediv>
|
||||
|
@ -40,8 +40,8 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$input = array ("a" => "green", "red", "b" => "green", "blue", "red");
|
||||
$result = array_unique ($input);
|
||||
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
|
||||
$result = array_unique($input);
|
||||
print_r($result);
|
||||
?>
|
||||
]]>
|
||||
|
@ -67,8 +67,8 @@ Array
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$input = array (4,"4","3",4,3,"3");
|
||||
$result = array_unique ($input);
|
||||
$input = array(4,"4","3",4,3,"3");
|
||||
$result = array_unique($input);
|
||||
var_dump($result);
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.array-unshift">
|
||||
<refnamediv>
|
||||
|
@ -35,8 +35,8 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$queue = array ("orange", "banana");
|
||||
array_unshift ($queue, "apple", "raspberry");
|
||||
$queue = array("orange", "banana");
|
||||
array_unshift($queue, "apple", "raspberry");
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.array-values">
|
||||
<refnamediv>
|
||||
|
@ -23,7 +23,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$array = array ("size" => "XL", "color" => "gold");
|
||||
$array = array("size" => "XL", "color" => "gold");
|
||||
print_r(array_values ($array));
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<!-- $Revision: 1.12 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.array-walk">
|
||||
<refnamediv>
|
||||
|
@ -75,23 +75,23 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
|
||||
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
|
||||
|
||||
function test_alter (&$item1, $key, $prefix) {
|
||||
function test_alter(&$item1, $key, $prefix) {
|
||||
$item1 = "$prefix: $item1";
|
||||
}
|
||||
|
||||
function test_print ($item2, $key) {
|
||||
function test_print($item2, $key) {
|
||||
echo "$key. $item2<br>\n";
|
||||
}
|
||||
|
||||
echo "Before ...:\n";
|
||||
array_walk ($fruits, 'test_print');
|
||||
array_walk($fruits, 'test_print');
|
||||
|
||||
array_walk ($fruits, 'test_alter', 'fruit');
|
||||
array_walk($fruits, 'test_alter', 'fruit');
|
||||
echo "... and after:\n";
|
||||
|
||||
array_walk ($fruits, 'test_print');
|
||||
array_walk($fruits, 'test_print');
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.110 -->
|
||||
<refentry id="function.array">
|
||||
<refnamediv>
|
||||
|
@ -47,9 +47,9 @@
|
|||
<![CDATA[
|
||||
<?php
|
||||
$fruits = array (
|
||||
"fruits" => array ("a"=>"orange", "b"=>"banana", "c"=>"apple"),
|
||||
"numbers" => array (1, 2, 3, 4, 5, 6),
|
||||
"holes" => array ("first", 5 => "second", "third")
|
||||
"fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"),
|
||||
"numbers" => array(1, 2, 3, 4, 5, 6),
|
||||
"holes" => array("first", 5 => "second", "third")
|
||||
)
|
||||
?>
|
||||
]]>
|
||||
|
@ -62,7 +62,7 @@ $fruits = array (
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$array = array( 1, 1, 1, 1, 1, 8=>1, 4=>1, 19, 3=>13);
|
||||
$array = array(1, 1, 1, 1, 1, 8 => 1, 4 => 1, 19, 3 => 13);
|
||||
print_r($array);
|
||||
?>
|
||||
]]>
|
||||
|
@ -98,7 +98,7 @@ Array
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$firstquarter = array(1 => 'January', 'February', 'March');
|
||||
$firstquarter = array(1 => 'January', 'February', 'March');
|
||||
print_r($firstquarter);
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.arsort">
|
||||
<refnamediv>
|
||||
|
@ -26,10 +26,10 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
|
||||
arsort ($fruits);
|
||||
reset ($fruits);
|
||||
while (list ($key, $val) = each ($fruits)) {
|
||||
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
|
||||
arsort($fruits);
|
||||
reset($fruits);
|
||||
while (list($key, $val) = each($fruits)) {
|
||||
echo "$key = $val\n";
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.asort">
|
||||
<refnamediv>
|
||||
|
@ -24,10 +24,10 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
|
||||
asort ($fruits);
|
||||
reset ($fruits);
|
||||
while (list ($key, $val) = each ($fruits)) {
|
||||
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
|
||||
asort($fruits);
|
||||
reset($fruits);
|
||||
while (list($key, $val) = each($fruits)) {
|
||||
echo "$key = $val\n";
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.compact">
|
||||
<refnamediv>
|
||||
|
@ -39,13 +39,13 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$city = "San Francisco";
|
||||
$city = "San Francisco";
|
||||
$state = "CA";
|
||||
$event = "SIGGRAPH";
|
||||
|
||||
$location_vars = array ("city", "state");
|
||||
$location_vars = array("city", "state");
|
||||
|
||||
$result = compact ("event", "nothing_here", $location_vars);
|
||||
$result = compact("event", "nothing_here", $location_vars);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.count">
|
||||
<refnamediv>
|
||||
|
@ -59,13 +59,13 @@
|
|||
$a[0] = 1;
|
||||
$a[1] = 3;
|
||||
$a[2] = 5;
|
||||
$result = count ($a);
|
||||
$result = count($a);
|
||||
// $result == 3
|
||||
|
||||
$b[0] = 7;
|
||||
$b[5] = 9;
|
||||
$b[0] = 7;
|
||||
$b[5] = 9;
|
||||
$b[10] = 11;
|
||||
$result = count ($b);
|
||||
$result = count($b);
|
||||
// $result == 3;
|
||||
?>
|
||||
]]>
|
||||
|
@ -80,8 +80,8 @@ $result = count ($b);
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$food = array( 'fruits' => array('orange', 'banana', 'apple'),
|
||||
'veggie' => array('carrot', 'collard','pea'));
|
||||
$food = array('fruits' => array('orange', 'banana', 'apple'),
|
||||
'veggie' => array('carrot', 'collard','pea'));
|
||||
|
||||
// recursive count
|
||||
echo count($food,COUNT_RECURSIVE); // output 8
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<!-- $Revision: 1.12 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.each">
|
||||
<refnamediv>
|
||||
|
@ -37,8 +37,8 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$foo = array ("bob", "fred", "jussi", "jouni", "egon", "marliese");
|
||||
$bar = each ($foo);
|
||||
$foo = array("bob", "fred", "jussi", "jouni", "egon", "marliese");
|
||||
$bar = each($foo);
|
||||
print_r($bar);
|
||||
?>
|
||||
]]>
|
||||
|
@ -65,8 +65,8 @@ Array
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$foo = array ("Robert" => "Bob", "Seppo" => "Sepi");
|
||||
$bar = each ($foo);
|
||||
$foo = array("Robert" => "Bob", "Seppo" => "Sepi");
|
||||
$bar = each($foo);
|
||||
print_r($bar);
|
||||
?>
|
||||
]]>
|
||||
|
@ -99,8 +99,8 @@ Array
|
|||
<?php
|
||||
$fruit = array('a' => 'apple', 'b' => 'banana', 'c' => 'cranberry');
|
||||
|
||||
reset ($fruit);
|
||||
while (list ($key, $val) = each ($fruit)) {
|
||||
reset($fruit);
|
||||
while (list($key, $val) = each($fruit)) {
|
||||
echo "$key => $val\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.end">
|
||||
<refnamediv>
|
||||
|
@ -26,7 +26,7 @@
|
|||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$fruits = array('apple','banana','cranberry');
|
||||
$fruits = array('apple', 'banana', 'cranberry');
|
||||
|
||||
print end($fruits); // cranberry
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.extract">
|
||||
<refnamediv>
|
||||
|
@ -163,10 +163,10 @@
|
|||
wddx_deserialize */
|
||||
|
||||
$size = "large";
|
||||
$var_array = array ("color" => "blue",
|
||||
"size" => "medium",
|
||||
"shape" => "sphere");
|
||||
extract ($var_array, EXTR_PREFIX_SAME, "wddx");
|
||||
$var_array = array("color" => "blue",
|
||||
"size" => "medium",
|
||||
"shape" => "sphere");
|
||||
extract($var_array, EXTR_PREFIX_SAME, "wddx");
|
||||
|
||||
print "$color, $size, $shape, $wddx_size\n";
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.56 -->
|
||||
<refentry id="function.in-array">
|
||||
<refnamediv>
|
||||
|
@ -43,11 +43,11 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$os = array ("Mac", "NT", "Irix", "Linux");
|
||||
if (in_array ("Irix", $os)) {
|
||||
$os = array("Mac", "NT", "Irix", "Linux");
|
||||
if (in_array("Irix", $os)) {
|
||||
print "Got Irix";
|
||||
}
|
||||
if (in_array ("mac", $os)) {
|
||||
if (in_array("mac", $os)) {
|
||||
print "Got mac";
|
||||
}
|
||||
?>
|
||||
|
@ -100,11 +100,11 @@ if (in_array(1.13, $a, TRUE)) {
|
|||
<?php
|
||||
$a = array(array('p', 'h'), array('p', 'r'), 'o');
|
||||
|
||||
if (in_array(array ('p', 'h'), $a)) {
|
||||
if (in_array(array('p', 'h'), $a)) {
|
||||
echo "'ph' was found\n";
|
||||
}
|
||||
|
||||
if (in_array(array ('f', 'i'), $a)) {
|
||||
if (in_array(array('f', 'i'), $a)) {
|
||||
echo "'fi' was found\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.5 $ -->
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.key">
|
||||
<refnamediv>
|
||||
|
@ -22,13 +22,12 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$array = array (
|
||||
'fruit1' => 'apple',
|
||||
'fruit2' => 'orange',
|
||||
'fruit3' => 'grape',
|
||||
'fruit4' => 'apple',
|
||||
'fruit5' => 'apple'
|
||||
);
|
||||
$array = array(
|
||||
'fruit1' => 'apple',
|
||||
'fruit2' => 'orange',
|
||||
'fruit3' => 'grape',
|
||||
'fruit4' => 'apple',
|
||||
'fruit5' => 'apple');
|
||||
|
||||
// this cycle echoes all associative array
|
||||
// key where value equals "apple"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.krsort">
|
||||
<refnamediv>
|
||||
|
@ -23,10 +23,10 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
|
||||
krsort ($fruits);
|
||||
reset ($fruits);
|
||||
while (list ($key, $val) = each ($fruits)) {
|
||||
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
|
||||
krsort($fruits);
|
||||
reset($fruits);
|
||||
while (list($key, $val) = each($fruits)) {
|
||||
echo "$key = $val\n";
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.ksort">
|
||||
<refnamediv>
|
||||
|
@ -23,10 +23,10 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
|
||||
ksort ($fruits);
|
||||
reset ($fruits);
|
||||
while (list ($key, $val) = each ($fruits)) {
|
||||
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
|
||||
ksort($fruits);
|
||||
reset($fruits);
|
||||
while (list($key, $val) = each($fruits)) {
|
||||
echo "$key = $val\n";
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.list">
|
||||
<refnamediv>
|
||||
|
@ -64,12 +64,12 @@ print "I need $power!\n";
|
|||
|
||||
<?php
|
||||
|
||||
$result = mysql_query ("SELECT id, name, salary FROM employees",$conn);
|
||||
while (list ($id, $name, $salary) = mysql_fetch_row ($result)) {
|
||||
print (" <tr>\n".
|
||||
" <td><a href=\"info.php?id=$id\">$name</a></td>\n".
|
||||
" <td>$salary</td>\n".
|
||||
" </tr>\n");
|
||||
$result = mysql_query("SELECT id, name, salary FROM employees",$conn);
|
||||
while (list($id, $name, $salary) = mysql_fetch_row($result)) {
|
||||
print(" <tr>\n" .
|
||||
" <td><a href=\"info.php?id=$id\">$name</a></td>\n" .
|
||||
" <td>$salary</td>\n" .
|
||||
" </tr>\n");
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.25 -->
|
||||
<refentry id="function.natsort">
|
||||
<refnamediv>
|
||||
|
@ -27,7 +27,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$array1 = $array2 = array ("img12.png", "img10.png", "img2.png", "img1.png");
|
||||
$array1 = $array2 = array("img12.png", "img10.png", "img2.png", "img1.png");
|
||||
|
||||
sort($array1);
|
||||
echo "Standard sorting\n";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.range">
|
||||
<refnamediv>
|
||||
|
@ -39,23 +39,23 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// array(0,1,2,3,4,5,6,7,8,9,10,11,12)
|
||||
// array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ,11, 12)
|
||||
foreach(range(0, 12) as $number) {
|
||||
echo $number;
|
||||
}
|
||||
|
||||
// The step parameter was introduced in 5.0.0
|
||||
// array(0,10,20,30,40,50,60,70,80,90,100)
|
||||
// array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
|
||||
foreach(range(0, 100, 10) as $number) {
|
||||
echo $number;
|
||||
}
|
||||
|
||||
// Use of character sequences introduced in 4.1.0
|
||||
// array('a','b','c','d','e','f','g','h','i');
|
||||
// array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i');
|
||||
foreach(range('a', 'i') as $letter) {
|
||||
echo $letter;
|
||||
}
|
||||
// array('c','b','a');
|
||||
// array('c', 'b', 'a');
|
||||
foreach(range('c', 'a') as $letter) {
|
||||
echo $letter;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.rsort">
|
||||
<refnamediv>
|
||||
|
@ -22,10 +22,10 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$fruits = array ("lemon", "orange", "banana", "apple");
|
||||
rsort ($fruits);
|
||||
reset ($fruits);
|
||||
while (list ($key, $val) = each ($fruits)) {
|
||||
$fruits = array("lemon", "orange", "banana", "apple");
|
||||
rsort($fruits);
|
||||
reset($fruits);
|
||||
while (list($key, $val) = each($fruits)) {
|
||||
echo "$key = $val\n";
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.shuffle">
|
||||
<refnamediv>
|
||||
|
@ -21,10 +21,10 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$numbers = range (1,20);
|
||||
srand ((float)microtime()*1000000);
|
||||
shuffle ($numbers);
|
||||
while (list (, $number) = each ($numbers)) {
|
||||
$numbers = range(1,20);
|
||||
srand((float)microtime()*1000000);
|
||||
shuffle($numbers);
|
||||
while (list(, $number) = each($numbers)) {
|
||||
echo "$number ";
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.sort">
|
||||
<refnamediv>
|
||||
|
@ -24,10 +24,10 @@
|
|||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$fruits = array ("lemon", "orange", "banana", "apple");
|
||||
sort ($fruits);
|
||||
reset ($fruits);
|
||||
while (list ($key, $val) = each ($fruits)) {
|
||||
$fruits = array("lemon", "orange", "banana", "apple");
|
||||
sort($fruits);
|
||||
reset($fruits);
|
||||
while (list($key, $val) = each($fruits)) {
|
||||
echo "fruits[".$key."] = ".$val."\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.uksort">
|
||||
<refnamediv>
|
||||
|
@ -27,16 +27,18 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
function cmp ($a, $b) {
|
||||
if ($a == $b) return 0;
|
||||
function cmp($a, $b) {
|
||||
if ($a == $b) {
|
||||
return 0;
|
||||
}
|
||||
return ($a > $b) ? -1 : 1;
|
||||
}
|
||||
|
||||
$a = array (4 => "four", 3 => "three", 20 => "twenty", 10 => "ten");
|
||||
$a = array(4 => "four", 3 => "three", 20 => "twenty", 10 => "ten");
|
||||
|
||||
uksort ($a, "cmp");
|
||||
uksort($a, "cmp");
|
||||
|
||||
while (list ($key, $value) = each ($a)) {
|
||||
while (list($key, $value) = each($a)) {
|
||||
echo "$key: $value\n";
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.12 $ -->
|
||||
<!-- $Revision: 1.13 $ -->
|
||||
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.usort">
|
||||
<refnamediv>
|
||||
|
@ -43,16 +43,18 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
function cmp ($a, $b) {
|
||||
if ($a == $b) return 0;
|
||||
function cmp($a, $b) {
|
||||
if ($a == $b) {
|
||||
return 0;
|
||||
}
|
||||
return ($a < $b) ? -1 : 1;
|
||||
}
|
||||
|
||||
$a = array (3, 2, 5, 6, 1);
|
||||
$a = array(3, 2, 5, 6, 1);
|
||||
|
||||
usort ($a, "cmp");
|
||||
usort($a, "cmp");
|
||||
|
||||
while (list ($key, $value) = each ($a)) {
|
||||
while (list($key, $value) = each($a)) {
|
||||
echo "$key: $value\n";
|
||||
}
|
||||
?>
|
||||
|
@ -96,7 +98,7 @@ $fruits[2]["fruit"] = "grapes";
|
|||
|
||||
usort($fruits, "cmp");
|
||||
|
||||
while (list ($key, $value) = each ($fruits)) {
|
||||
while (list($key, $value) = each($fruits)) {
|
||||
echo "\$fruits[$key]: " . $value["fruit"] . "\n";
|
||||
}
|
||||
?>
|
||||
|
@ -140,7 +142,9 @@ class TestObj {
|
|||
{
|
||||
$al = strtolower($a->name);
|
||||
$bl = strtolower($b->name);
|
||||
if ($al == $bl) return 0;
|
||||
if ($al == $bl) {
|
||||
return 0;
|
||||
}
|
||||
return ($al > $bl) ? +1 : -1;
|
||||
}
|
||||
}
|
||||
|
@ -149,10 +153,10 @@ $a[] = new TestObj("c");
|
|||
$a[] = new TestObj("b");
|
||||
$a[] = new TestObj("d");
|
||||
|
||||
usort($a, array ("TestObj", "cmp_obj"));
|
||||
usort($a, array("TestObj", "cmp_obj"));
|
||||
|
||||
foreach ($a as $item) {
|
||||
print $item->name."\n";
|
||||
print $item->name . "\n";
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
|
|
Loading…
Reference in a new issue