PHP Chinese function serialization (2)-PHP source code

Source: Internet
Author: User
Ec (2); function count () Description: calculate the number of elements in a variable intcount (mixedvar); Returnsthenumberofelementsinvar, whichistypicallyanarray (sinceanythingelsewillhaveoneelement ). returns0ifthevariable script ec (2); script

Function count ()
Description:
Calculate the number of elements in a variable.
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.

Function current ()
Description:
Returns the elements currently referred to by the array pointer.

Mixed current (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.

Function each ()
Description:
Returns the value of the next key/value in the array.

Array each (array );

Returns the current key/value pair from the 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:
";
While (list ($ key, $ val) = each ($ HTTP_POST_VARS )){
Echo "$ key => $ val
";
}

Function end ()
Description:
Move the pointer in the array to the last one.
End (array );
End () advances array's internal pointer to the last element.

Function key ()
Description:
Retrieve keys from an array
Mixed key (array );
Key () returns the index element of the current array position.

Function ksort ()
Description:
Sort an array by 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]. "";}

This example wocould display: fruits [a] = orange fruits [B] = banana fruits [c] = apple fruits [d] = lemon

Function list ()
Description:
Specify the value of a whole string of variables in an array-like manner.
Example 1. list () example







While (list ($ id, $ name, $ salary) = mysql_fetch_row ($ result )){Print (" "." "." "." ");}?>
Employee name Salary
$ Name$ Salary

Function next ()
Description:
Pointing an array to the next group of data


Function pos ()
Description:
Returns the current data of the array.

Function prev ()
Description:
Returns the data of the first row of the array.

Function reset ()
Description:
The pointer to the array refers to the first one.

Function rsort ()
Description:
Arrange an array in inverted order
Example 1. rsort () example

$ Fruits = array ("lemon", "orange", "banana", "apple ");
Rsort ($ fruits );
For (reset ($ fruits); ($ key, $ value) = each ($ fruits );){
Echo "fruits [$ key] =". $ value ."";
}

This example wocould display: fruits [0] = orange fruits [1] = lemon fruits [2] = banana fruits [3] = apple The fruits have been sorted in reverse alphabetical order.

Function sizeof ()
Description:
Returns the size and number of elements of an array.

Function sort ()
Description:
Sort Array
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]. "";
}

This example wocould display: fruits [0] = apple fruits [1] = banana fruits [2] = lemon fruits [3] = orange The fruits have been sorted in alphabetical order.

Function uasort ()
Description:
Arrange an array in a custom manner without changing the sequence.


Function uksort ()
Description:
Sort by key in a custom manner
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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.