PHP Basic Function Example Detailed

Source: Internet
Author: User
This article is mainly to share with you the PHP basic function Examples of the detailed, I hope to help everyone.

1, the function of the output:

L print (): Similar to what the Echo output provides, returns 1

L Print_r () is generally used for printing arrays , not printing types

L Var_dump (): The value of the printed data, as well as the type

2. Functions related to TIME

L Date (): Display datetime

Example: Date ("Y-m-dh:i:s")

L Time (): Timestamp (number of seconds)

L microtime (): Returns the timestamp and the number of microseconds

L strtotime (): Parses a datetime string into a timestamp

3. Mathematical Correlation function:

L Max ($v 1, $v 2, $v 3 ...) max.

L min ($v 1, $v 2, $v 3 ...) minimum value

L rand () random number

L Mt_rand () to generate better random numbers

L round (variable [, N]) keep N bit small

L ceil () rounding up

L floor () rounding down

L POW (x, y) Seek xy

L ABS () absolute value

L sqrt (): Seek square root

4. Functions related to functions

L function_exists (' function name ') to determine if a function exists

L Func_get_arg (subscript) gets the parameter corresponding to the specified subscript

L Func_get_args (): Gets all the parameters in the custom function (the return value is an array)

L Func_num_args (): Gets the number of arguments for the current custom function

5. String-related functions

Basic function strlen (): Gets the length of the string Mb_strlen($ string variable name, character encoding)

L Implode (connection mode, array): Concatenate into a string

L explode(split character, Target string): into an array

L Str_split (string, character length): Splits a string by a specified length to get an array

Trim (string [, specified character]): The default is to remove spaces on both sides of the string

L LTrim (): Remove the Left

L RTrim (): Remove the right

L substr(string, start position starting from 0 [, length])

L strstr(string, match character): Start at the specified position, intercept to the last (can be used to go to the file suffix name)

L Strtolower (): All lowercase

L Strtoupper (): All caps

L Ucfirst (): Capitalize first letter

L Strpos (string, match character): determines where the character appears in the target string (first time)

L Strrpos (string, match character)

L Str_replace (match target, replace content, string itself)

L printf/sprintf (the output string has placeholders, order placeholder content ...) %d%s

L str_repeat (): Repeats a string n times

L str_shuffle (): Randomly scrambled string

6. Array-related functions

functions for sorting arrays

L Sort (): Sort ascending by the value of the element ( subscript reorder)

L rsort (): Descending by the value of the element ( subscript reorder)

L Asort (): Sort ascending by the value of the element (subscript reserved)

L arsort (): Descending by the value of the element (subscript reserved)

L ksort (): Array key Name (subscript) in ascending order (subscript reserved)

L krsort (): Key names in descending order, (subscript reserved)

L Shuffle (): Random scrambling of array elements, bidding clubs rearrangement under array

L Sort: The default is in ascending order, with R is descending order )

L have a: is to keep the index relationship

L k: Sort by key name

Pointer

Reset () resets the pointer and returns the array pointer to the first

L End () resets the pointer, pointing the array pointer to the last element

L next () pointer moves down to get the value of the next element

L prev () pointer moves up to get the value of the previous element

L current (): Gets the value of the element that is currently in the pointer (does not move the pointer)

L Key (): Gets the subscript value corresponding to the current pointer (does not move the pointer)

Array other functions

L count (): counts the number of elements in the array

L Array_push (): Add an element to the array (after the array)

L array_pop (): Remove an element from the array (after the array)

L array_shift (): Remove an element from the array (front of the array)

L Array_unshift (): Add an element from the array (before the array)

L array_reverse (): array elements in turn

L In_array (): Determines whether an element exists in the array

L Array_keys (): Gets all the subscripts of an array, returns an indexed array

L array_values (): Gets all the values of an array, returns an indexed array

L array_merge (): merges one or more arrays

Array_merge ($arr 1, $arr 2)

L array_splice (): Remove part of the array and replace it with other values

$input = Array ( , "green"
array_splice Span style= "color: #007700;" > ( $input , 2 );

//$input is now array(“red”,”Green”);

L array_chunk (): splits an array into multiple

L Shuffle (): disturb the array

L Range (): creates an array containing the specified range of cells

L is_file (): determine if the given file name is a normal file

L define (): defines a constant

L defined (): checks for the existence of a constant of a name

L ini_set (): set a value for a configuration optionini_set('display_errors', '1');

L basename (): returns the file name portion of the path

L Is_array (): detects if the variable is an array

L List (): assigns the values in the array to some variables

$info = array('coffee', 'brown', 'caffeine');
list($drink, $color, $power) = $info;
echo "$drink is $color and $power makes it special.\n";

L nl2br (): insert HTML wrap tag before all new lines in string

L Array_rand (): random extraction of one or more cells from an array

L count (): counts the number of cells in an array or the number of attributes in an object

L Reset (): points The inner pointer of the array to the first cell

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.