I don't know how PHP beginners learn functions, but I think learning functions must be objective-driven. taking array functions as an example! How can we learn so many array functions? In fact, we only need to be clear, we need to do what operations on the array, and then classify these operations, the heart has a general impression, and then with your real "> <LINKhref =" http://www.php100.com
I don't know how PHP beginners learn function numbers, but I think it must be purposeful. it is objective-driven. take array functions 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 the array, and then classify these operations, so we have a general impression in our hearts. then, with your practice, you will be very clear about these functions. here, I would like to remind you that the manual should be retained! Not to mention, array functions are generally classified into the following categories (do not be afraid of English ):
Outputting arrays
Creating arrays
Testing for an array
Locating array elements
Traversing arrays
Determining array size and element uniqueness
Sorting arrays
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 ();
ArrayRange(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 an array
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 ()
IntArray_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!
Example:
Copy the PHP content to the clipboard. PHP code:
$states =array(‘Ohio’, ‘New York’);
array_push($states, ‘California’,‘Texas’);
//output: array((‘Ohio’,‘New York’ , ‘California’,‘Texas’);
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!
Example:
Copy the PHP content to the clipboard. PHP code:
$states =array(‘Ohio’, ‘New York’);
$state = array_pop($states);
//output: New York
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 ();
ArrayArray_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 ();
ArrayArray_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 ();
BoolArray_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 ();
ArrayArray_values(Array input)
Similar to array_keys! All key values of the array are returned!
Array_search ();
MixedArray_search(Mixed needle, array haystack [, bool strict])
Search for the needle parameter in haystack and return the key name if it is found. 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!