PHP Most full note (three) (worth collecting, check it through)

Source: Internet
Author: User
Tags autoload

/* "Array function" *///statistical calculation
Count counts the number of cells in an array or the number of properties in an object
Array_count_values the number of occurrences of all values in the statistics array
Array_product computes the product of all values in an array
Array_sum computes the and of all values in the array
Range creates an array containing the specified range of cells Array_chunk splits an array into multiple
Array Array_chunk (array $input, int $size [, bool $preserve _keys]) Array_filter filters the cells in the array with a callback function Array_slice take a paragraph out of the array
Array Array_slice ($arr, $offset [, $len [, $preserve _keys]] Array_keys returns all the key names in the array
Array Array_keys (array $input [, mixed $search _value[, BOOL $strict]])
If an optional parameter, Search_value, is specified, only the key name of the value is returned. Otherwise all the key names in the input array will be returned. Array_values returns all values in the array and establishes a numeric index

Array_merge merging one or more arrays

The values in an array are appended to the back of the previous array.

If the input array has the same string key name, the value following the key name overrides the previous value.

If the array contains numeric key names, subsequent values will not overwrite the original values, but are appended to the back.

If only one array is given and the array is a numeric index, the key name is re-indexed in a sequential manner. Array_merge_recursive to merge one or more arrays recursively

Search

In_array checks if a value exists in the array

BOOL In_array (mixed $needle, array $haystack [, bool$strict]) array_key_exists checks whether the given key name or index exists in the array

Isset () does not return true for values that are null in the array, and array_key_exists () Array_search searches the array for the given value and returns the corresponding key name if successful

Array_combine creates an array with the value of an array as its key name, and the value of another array as its value

Returns False if the number of cells in the two array is different or if the array is empty. Array_rand randomly extracts one or more cells from an array, returns an array of key names or key names, and the subscripts are naturally ordered

Array_fill fills an array with the given value

Array_fill ($start, $num, $value) Array_flip the key and value in the interchange array Array_pad fills the array to a specified length with a value array_reverse returns an array of cells in reverse order Array_un Ique duplicate values in an array array_splice remove some of the arrays and replace them with other values

Implode concatenate array element values with a string explode ($delimiter, $str [, $limit])//Split another string with one string

$delimiter cannot be an empty string ""

Array_map the callback function to the cell of the given array, only the element value can be processed and multiple arrays

If the callback parameter is set to NULL, merging multiple arrays into a multidimensional array

Array_walk applies a user function to each member of an array, can handle only one of the arrays, the key and the value can be processed, the same as the Foreach function

BOOL Array_walk (array & $array, callback $funcname [, mixed $userdata])

Stack:

LIFO and outbound Stacks redistribute index subscript array_push pushes one or more cells into the end of the array (into the stack) Array_pop the last cell of the array is popped (out of the stack) using this function resets the (reset ()) array pointer.

Queue:

The FIFO queue function will reassign the index subscript array_unshift inserts one or more cells at the beginning of the array array_shift the cells beginning with the array are removed by using this function, the array pointer is reset (reset ()).

Sort function

sort             sorting an array rsort              reverse order of logarithmic groups asort              sorting an array and keeping the index relationship arsort              Reverse-Sort an array and keep the index relationship ksort             The array is sorted by key name krsort             array is reversed by key name usort              sort the values in an array using a user-defined comparison function uksort              sort the key names in the array using a user-defined comparison function uasort              use a user-defined comparison function to sort the values in the array and keep the index associated natsort              sorting arrays using the "natural sort" algorithm natcasesort          Use the "natural sort" algorithm to do an array ofSort the case-sensitive letters array_multisort  multiple arrays or multidimensional arrays shuffle              scrambled Arrays

A reference pass parameter that returns a bool value.

Re-assign the index key name, delete the original key name

Subtraction

ARRAY_UDIFF_ASSOC Index Check the difference set of the computed array, using the callback function to compare the data Array_udiff_uassoc with the index check the difference set of the array, using the callback function to compare the data and the index Array_udiff use the callback function to compare the data to calculate the array Difference set of ARRAY_DIFF_ASSOC with index check of computed array

Array_diff_key using the key name to compare the difference set of the computed array ARRAY_DIFF_UASSOC use the user-provided callback function to do index checking to calculate the difference set of the array

Array_diff_ukey using a callback function to compare the difference set of a computed array array_diff the difference//intersection of a computed array array_intersect_assoc the intersection of the computed array with an index check

Array_intersect_key using the key name to compare the intersection of the computed array Array_intersect_uassoc the intersection of the computed array with the index check, using the callback function to compare the index

Array_intersect_ukey uses the callback function to compare the key names to compute the intersection of the arrays Array_intersect computes the intersection of the array array_key_exists computes the intersection of the arrays with the callback function to compare the key names array_uintersect_ Assoc the intersection of the computed array with the index check, compares the data with the callback function Array_uintersect computes the intersection of the array, compares the data with the callback function

Extract ($arr [, $type [, $prefix]] imports a variable from an array into the current symbol table (accepts associative array $arr as a parameter and takes the key name as the variable name, value as the value of the variable) compact ($var [,...]) Create an array, including the variable names and their values (the variable name becomes the key name and the contents of the variable become the value of the key)

/* "Pseudo type" */

Mixed shows that a parameter can accept a variety of different (but not all) types. Number indicates that a parameter can be an integer or float. Callback callback function

void void, as a return type, means that the return value of a function is useless.

void as a parameter list means that the function does not accept any arguments.

/* Database Operations */

#连接认证mysql_connect Connect and certify database # Send SQL statement, receive execution result mysql_query send SQL statement

Only for Select, show, explain, describe statement execution successfully returns a resource identifier, and other statements successfully return TRUE. Execution failure returns false. #处理结果mysql_fetch_assoc get a row from the result set as an associative array

Retrieve only one at a time, similar to each

Result set record pointer mysql_fetch_row takes a row from the result set as an enumeration array mysql_fetch_array gets a row from the result set as an associative array, or as a numeric array, or both

Array mysql_fetch_array (Resource $result [, int $ result_type])

Optional parameters Result_type Optional values are: Mysql_assoc,mysql_num and Mysql_both (default) Mysql_free_result release result memory # Close link Mysql_close close connection

/* Classes and objects */

# Members: Class Members: Class constants, static properties, static methods

Object members: Non-static properties, non-static methods

# except in addition, the class cannot contain anything else!!!

# class names, method names, property names are case-insensitive

# $this represents this object, the self represents the class, and the parent represents the parental class

# classes and functions can be compiled beforehand (only as outermost)

# class must be defined within a single PHP block and cannot be separated by multiple PHP tags

Construction method

-Classes with constructors call this method each time a new object is created

void __construct ([Mixed $args [, $ ...]) -the constructor method adds parameter values to the class when it instantiates the object by new. -Construction methods can also be called manually. -5.3. Prior to version 3, methods that supported the same name as the class names were used as construction methods. -__construct priority in two conflicts

destructor method

-Destructors are removed when all references to an object are deleted or executed when the object is explicitly destroyed.

void __destruct (void) # Action: Frees resources occupied by objects

# Time to call

-All resources are freed at the end of the script, including the object

-When deleting objects manually

-When the variable that holds the object is given a new value (any value, including null)

-will also be called when the script is run with exit ()

static member (static keyword)

-declares that a class member or method is static and can be accessed directly without instantiating the class.

-Static members (properties or methods) belong to the class and cannot be accessed through $this or.

-Static members are all objects shared and belong to classes.

-static members are called with the class, and non-static members are invoked with objects. # Static Properties

-Static properties cannot be accessed by the object by operator.

-A static property can only be initialized to a character value or a constant and cannot be used with an expression. So you can initialize a static property to an integer or an array, but you can't point to another variable or function return value, or point to an object. # static method

-Because static methods do not need to be called through an object, the pseudo-variable $this is not available in a static method.

-Invoking a non-static method with:: Mode causes a e_strict level of error.

Access resolution operator (::)

-can be used to access static members, methods, and constants, and can also be used to override members and methods in a class.

-When you access these static members, methods, and constants outside of the class, you must use the name of the class.

-The two special keywords, self and parent, are used to access members or methods within a class.

Access discrimination

-the object member, which is specified internally through $this, is accessed by using the object name, and access to the property is not required.

Object name, property name Object name, method name () $this Property name $this method Name ()-class member, internally specified by self or parent, externally specified by the class name, by using:: Access, Access property is required.

Class Name:: $ property Name Class Name:: Method Name () self::$ property name Self:: Method name ()-Special: The class member can also be accessed through an object. (Not recommended)

Object Name:: $ class Property name $this:: $ class Property Name Object Name:: $ class Method Name () $this:: Class Method Name () # object member access with->, class member Access by::

-both static and non-static methods can be accessed through a class or object. -static properties are accessed through the class, and static methods are accessed through the object. -$this can only be used if a non-static method is invoked using an Object! -Static methods cannot use $this. -The class can call the object method, but notice that there is no $this in the method. -A non-static method can call a static property or a static method, and vice versa.

Class constants

-The value of the constant will always remain unchanged. -You do not need to use the $ symbol when defining and using constants. -The value of a constant must be a fixed value and cannot be the result of a variable, class property, or other operation, such as a function call. # definition: const constant name = constant value;

-No need to add public such as access modifier qualifier-class constants belong to class, use class Access, class Name:: Class constant or Self:: class constant

Automatically load objects

-Automatically invoke the __autoload function when trying to use a class that has not yet been defined-automatically load the used class name file (depending on the class name to find the corresponding name of the file, so that the class name and the class name match)-every file that needs to load the class needs to have the __autoload function-will __ The AutoLoad function writes to a separate file, each file that needs to be used for the class require the function file-the __autoload parameter is the class name function __autoload ($class _name) {

require_once $_server["Document_root"]. "/class/$class _name.php";

}

$_server["Document_root"] the document root directory where the script is currently running

-You can deduce the name of the class by using the class name! -If there is more than one auto-loading function for an item, define a normal function that can be loaded, and register the function with Spl_autoload_register before the function. # Spl_autoload_register

-register __autoload () function

BOOL Spl_autoload_register ([callback $autoload _function])-Multiple auto-load functions can be registered, first executed first-once the auto-load function is registered, __autoload fails. -When registering a function, the parameter is the function name (note the quotation marks); When you register a method, the parameter is an array of methods for the automatic load method, and the parameter is an array of parameters:

Spl_autoload_register (Array (__class__, ' __autoload '));

__CLASS__ represents the current class name, if the object is available $this, see the Manual for details

PHP Most full note (three) (worth collecting, check it through)

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.