PHP Chinese function serialization (2)

Source: Internet
Author: User
Function count () description: calculate the number of elements in a variable intcount (mixedvar); Returnsthenumberofelementsinvar, whichistypicallyanarray (sinceanythingelsewillhaveoneelement

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', 'secpo' => 'secpi'); $ 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' => 'limon', 'a' => 'Orange ',' B '=> 'bana ', 'C' => 'apple ');
Ksort ($ fruits );
For (reset ($ fruits );
$ Key = key ($ fruits );
Next ($ fruits) {echo 'Fruits [$ key] = '. $ fruits [$ key].' \ n ';}


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


Function list ()

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.