函數count()
描述:
計算一變量中元素的個數
int count (mixed var);
returns the number of elements in var , which is typically an array (since anything else will have one element).
returns 0 if the variable is not set.
returns 1 if the variable is not an array.
函數current()
描述:
傳回數組指針目前所指的元素
mixed current (array array);
each array variable has an internal pointer that points to one of its elements. in addition, all of the elements in the array are linked by a bidirectional linked list for traversing purposes. the internal pointer points to the first element that was inserted to the array until you run one of the functions that modify that pointer on that array.
the current() function simply returns the array element that's currently being pointed by the internal pointer. it does not move the pointer in any way. if the internal pointer points beyond the end of the elements list, current() returns false.
函數each()
描述:
返回數組中下一對key/value的值
array each (array array);
returns the current key/value pair from the array array and advances the array cursor. this pair is returned in a four-element array, with the keys 0 , 1 , key , and value . elements 0 and key each contain the key name of the array element, and 1 and value contain the data.
example 1. each() examples
$foo = array( "bob", "fred", "jussi", "jouni" ); $bar = each( $foo );
$bar now contains the following key/value pairs:
0 => 0
1 => 'bob'
key => 0
value => 'bob'
$foo = array( "robert" => "bob", "seppo" => "sepi" ); $bar = each( $foo );
$bar now contains the following key/value pairs:
0 => 'robert'
1 => 'bob'
key => 'robert'
value => 'bob'
example 2. traversing $http_post_vars with each()
echo "values submitted via post method:<br>";
while ( list( $key, $val ) = each( $http_post_vars ) ) {
echo "$key => $val<br>";
}
函數end()
描述:
將數組中的指針移到最后一個
end (array array);
end() advances array 's internal pointer to the last element.
函數key()
描述:
從一數組中取出key
mixed key (array array);
key() returns the index element of the current array position.
函數ksort()
描述:
以key來排列一數組
example 1. ksort() example
$fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");
ksort($fruits);
for(reset($fruits);
$key = key($fruits);
next($fruits)) { echo "fruits[$key] = ".$fruits[$key]."/n"; }
this example would display: fruits[a] = orange fruits[b] = banana fruits[c] = apple fruits[d] = lemon
函數list()
描述:
用類似數組的方式去指定一整串變量的值
example 1. list() example
<table> <tr> <th> employee name</th>
<th>salary</th> </tr>
<?php $result = mysql($conn, "select id, name, salary from employees");
while (list($id, $name, $salary) = mysql_fetch_row($result)) {
print(" <tr>/n"."<td><a href=/"info.php3?id=$id/">$name</a></td>/n"."<td>$salary</td>/n"." </tr>/n");
}
?>
</table>
函數next()
描述:
將數組的指向指到下一組數據
函數pos()
描述:
傳回數組的當前的數據
函數prev()
描述:
傳回數組的前一條的數據
函數reset()
描述:
數組的指針指到第一條
函數rsort ()
描述:
以倒序方式排列一個數組
example 1. rsort() example
$fruits = array("lemon","orange","banana","apple");
rsort($fruits);
for(reset($fruits); ($key,$value) = each($fruits); ) {
echo "fruits[$key] = ".$value."/n";
}
this example would display: fruits[0] = orange fruits[1] = lemon fruits[2] = banana fruits[3] = apple the fruits have been sorted in reverse alphabetical order.
函數sizeof()
描述:
取得一個數組的大小和元素的數目
函數sort()
描述:
排序數組
example 1. sort() example
$fruits = array("lemon","orange","banana","apple");
sort($fruits);
for(reset($fruits);
$key = key($fruits);
next($fruits)) {
echo "fruits[$key] = ".$fruits[$key]."/n";
}
this example would display: fruits[0] = apple fruits[1] = banana fruits[2] = lemon fruits[3] = orange the fruits have been sorted in alphabetical order.
函數uasort()
描述:
以自定義的方式排列一個數組且序列不變。
函數uksort()
描述:
以自定義的方式以key排列
this function will sort the keys of an array using a user-supplied comparison function. if the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function. example 1. uksort() example
function mycompare($a, $b) {
if ($a == $b) return 0;
return ($a > $b) ? -1 : 1;
}
$a = array(4 => "four", 3 => "three", 20 => "twenty", 10 => "ten");
uksort($a, mycompare);
while(list($key, $value) = each($a)) {
echo "$key: $value/n";
}
this example would display: 20: twenty 10: ten 4: four 3: three
函數usort()
描述:
以自定義的方式以value排列
void usort (array array, function cmp_function);
this function will sort an array by its values using a user-supplied comparison function. if the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function. example 1. usort() example
function cmp($a,$b) {
if ($a == $b) return 0;
return ($a > $b) ? -1 : 1;
}
$a = array(3,2,5,6,1);
usort($a, cmp);
while(list($key,$value) = each($a)) {
echo "$key: $value/n";
}
this example would display: 0: 6 1: 5 2: 3 3: 2 4: 1 obviously in this trivial case the rsort() function would be more appropriate.
bc (arbitrary precision) functions
函數bcadd()
描述:
add two arbitrary precision numbers
string bcadd (string left operand, string right operand, int [ scale ]); 左面的字符加右面的字符,返回一個字符。
函數bccomp()
描述:
int bccomp (string left operand, string right operand, int [ scale ]);
左面的字符和右面的字符進行比較,如果相等的話返回0,如果左面的比右面的長返回+1,右面的比左面的長返回-1
函數bcdiv()
描述:
divide two arbitrary precision numbers
string bcdiv (string left operand, string right operand, int [ scale ]); 將左面的字符串以右面的字符串為標準分開
函數bcmod()
描述:
get modulus of an arbitrary precision number
string bcmod (string left operand, string modulus);
用右面的modulus操作左面的字符串
函數bcmul()
描述:
multiply two arbitrary precision number
string bcmul (string left operand, string right operand, int [ scale ]);
multiply the left operand by the right operand and returns the result. the optional scale sets the number of digits
after the decimal place in the result.
函數bcpow()
描述:
raise an arbitrary precision number to another.
raise x to the power y . the scale can be used to set the number of digits after the decimal place in the result.
函數bcscale()
描述:
set default scale parameter for all bc math functions.
string bcscale (int scale);
this function sets the default scale parameter for all subsequent bc math functions that do not explicitly specify a scale
parameter
函數bcsqrt()
描述;
string bcsqrt (string operand, int scale);
返回字符的平方根
函數bcsub()
描述:
string bcsub (string left operand, string right operand, int [ scale ]);
將右面的字符減去左面的字符
calendar functions日歷功能
函數jdtogregorian()
描述:
string jdtogregorian (int julianday);
將julian日歷轉換成gregorian日歷
函數gregoriantojd()
描述:
int gregoriantojd (int month, int day, int year);
將gregorian日歷轉換成julian日歷
函數jdtojulian ()
描述:
string jdtojulian (int julianday);
將julian calendar轉換julian day
函數juliantojd ()
描述:
int juliantojd (int month, int day, int year);
函數jdtojewish ()
描述:
converts a julian day count to the jewish calendar
string jdtojewish (int julianday);
函數jewishtojd()
描述:
converts a date in the jewish calendar to julian day count
int jewishtojd (int month, int day, int year);
函數jdtofrench()
描述:
converts a julian day count to the french republican calendar
string jdtofrench (int month, int day, int year);
函數frenchtojd()
描述:
converts a date from the french republican calendar to a julian day count int frenchtojd (int month, int day, int year);
函數jdmonthname ()
描述:
returns a month name
string jdmonthname (int julianday, int mode);
mode meaning
0 gregorian - apreviated
1 gregorian
2 julian - apreviated
3 julian
4 jewish
5 french republican
函數jddayofweek ()
描述:
returns the day of the week
mixed jddayofweek (int julianday, int mode);
mode meaning
0 returns the day number as an int (0=sunday, 1=monday, etc)
1 returns string containing the day of week (english-gregorian)
2 returns a string containing the abreviated day of week (english-gregorian)
新聞熱點
疑難解答