PHP Basic Syntax (control statements, arrays, functions)

Source: Internet
Author: User
Tags function definition

Process Control if-else if-else statement: Switch statement: while loop: Do and loop for loop: controlling script Execution Progress

Die("Output content")

Exit is synonymous with die.

Sleep ($n);

meaning: Let the php script stop $n seconds before proceeding.

Array Basics

In PHP, the subscript of an array can be an integer, or a string.

in PHP, the order of elements in an array is not determined by the subscript, but by the order in which they "join".

Associative arrays:

Usually refers to an array that is labeled as a string, and that string can roughly express the meaning of the data.

Example:$person = Array (

"Name" = "Floret",

"Age" =>18,

"Edu" = "University Graduate" ,

);

indexed Arrays:

usually refers to the subscript of an array is a strict 0-based continuous digital subscript-As with the JS Array.

Value: Pass the subscript.

Assignment (same definition):

Array Traversal

A foreach ($arr as [$key = =] $value)//$key can be called a key variable,$value can be called a value variable.

{

Here you can do all the possible things for $key and $value -because they are a variable

$key represents every time an index of an element is obtained, possibly a number, or it can be a string

$value represents the value of the element each time it is acquired, possibly various types.

This loop structure iterates through the first item of the array, loops to the last item, and then ends.

}

function Definition Form

function function name ( parameter 1, parameter 2,...) {

function Body (code block)

}

functions Call: function name ( argument 1, argument 2, ....); the number of arguments should be matched with the formal parameter.

Default value parameter parameter-value problem of function number of parameters problem

Func_get_args (); get all the argument data that a function receives, and the result is an array

Func_get_arg (n); obtains the nth argument data received by a function (n starts from 0 )

Func_num_args (); gets the number of all the argument data received by a function

return value of the function

Typically, in a function, with a return statement, with a data, the function returns the data to the "location of the call"

system functions related to functions:

Function_exists (): Determines whether a function has been defined, returns a Boolean value

if (function_exists ("func1") = = False) {

function Func1 () {... };// define functions

}

Func_get_arg (n): Gets the nth argument value of a function (n starts from 0 )

Func_get_args (): Gets all the arguments of a function, the result is an array

Func_num_args (): Gets the number of all arguments for a function.

PHP Basic Syntax (control statements, arrays, functions)

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.