Summary of array functions in PhP5

Source: Internet
Author: User

I don't know how PHP beginners learn letters.
Number, but I think it must be purposeful to learn it. It is objective-driven. Take the array function as an example! How can we learn so many array functions? In fact, we only need to know what operations we need to perform on arrays.
And then classify these operations, and you will have a general impression in your mind. Then, with your practice, you will be very clear about these functions. Here, I would like to remind you that the manual should be kept up! Array functions are generally classified
The following types (do not be afraid of English ):
Outputting Arrays
Testing for an array
Locating array elements
Determining array size and element uniqueness
Merging, slicing, splicing, and dissecting Arrays

Outputting Arrays
Print_r ()
If I am not familiar with this, I don't want to say more! The most basic function, of course, Outputs An array but uses a loop structure for output. But why not use this convenient output function!

Creating Arrays
Array ()
I don't want to talk about this function either. In fact, this function can only be regarded as a language structure. You have used it when creating arrays. If you have never used it, You can only say it, bro, I'm speechless!
List ()
This function is just a language structure like the Array () mentioned above. It assigns values to a group of variables in one step!
For more information, see the manual!
Range ();
Mixed low, mixed high [, number step])
Creates an array containing a specified range of units.
Example: $ arr = range (0,
6 );
Equivalent to $ arr = array (0, 1, 2, 3, 4, 5, 6 );
Generally, data is arranged from low to high. If low> high, data is arranged from high to low;

Testing for
Is_array ();
Test whether the variable is of the array type. If yes, true is returned. If not, false is returned. It is a basic and practical function!

Adding and removing array elements
Array_push ()
Array_push(Array & target_array, mixed var [, mixed...]
Add one or more cells to the array from the end! Returns the total number of cells in the new array!

Copy the PHP content to the clipboard.

PHP code:

$states =array(‘Ohio’,
‘New York’);
//output: array((‘Ohio’,‘New York’ ,

Array_pop ();
The last cell of the array is displayed and returned, and the length of the array is reduced by one. The array pointer is reset after use!

Copy the PHP content to the clipboard.

PHP code:

$states =array(‘Ohio’,
‘New York’);
$state =
//output: New

Array_shift ();
It is similar to array_pop, except that it removes and returns the first value of the array. The number key will record data from scratch, and the text key name will remain unchanged!

Array_unshift ();
Similar to array_push, data is inserted from the array header! The number key will record data from scratch, and the text key name will remain unchanged!

Array_pad ();
Array_pad(Array input, intpad_size, mixed pad_value
Fill the array with the specified length!
If pad_size is positive, it is filled from the right, negative, left, small, and array length! For examples, see the manual!

Locating array elements
In_array ();
Check whether a value exists in the array. For more information, see the manual!

Array_keys ();
Array_keys(Array input [, mixed search_value [, bool strict]
Returns all key names in the array. If search_value is selected, the selected key name is returned! From PHP
5], you can use the strict parameter for full comparison (= ).

Array_key_exists ();
Array_key_exists(Mixed key, array search)
Check whether the given key name or index exists in the array. If yes, true is returned. For more specific applications, see the manual!

Array_values ();
Array_values(Array input)
Similar to array_keys! All key values of the array are returned!

Array_search ();
Array_search(Mixed needle, array haystack [, bool strict]
Search in haystack
If the needle parameter is found, the Return key is returned. OtherwiseFalse.
If needle is a string, it is case sensitive!
If strict is true, the comparison type is required.
If needle appears more than once in haystack, the first matched key is returned. To return keys of all matched values, replace array_keys () with the optional parameter search_value!

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: 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.