Getting Started with PHP

Source: Internet
Author: User

1. Two ways of marking and annotation

Single-line Comment

/* Multiline Comment */

2. Output statement

echo Output:echo can output multiple strings, separated by commas

Print output: Print can output only one string, which returns TRUE or False

Print_r (): You can simply print the string and the number, and the array is displayed in the enclosed key and the list of merit, and in array

Var_dump (): Output Variable type information

3. Data type definition variables

  3.1 PHP is a weak type, the variable does not have a definite type

Definition: $ variable name = value; The $ variable name is whole and requires an overall operation

Data types in PHP are reflected in the values

$a = 10;

$b = "he{$a}llo";

$c = ' world ';

1. Double quotation mark inside can parse escape character, single quotation mark not

2. Double quotation mark inside can parse variable, single quotation mark not

 3.2 Third definition string, output full content, no escape characters, etc.

$d = <<<aa

Hello "AA", "BB", ' CC ',

<input type= "text" value= "AA"/>

    aa;*/

 3.3 $e = $a. $c; Stitching strings with the.

3.4 Data type conversion, not strong, PHP is a weak type, you have become the past

$f = 10.05;

$f = (string) $f; Type conversions

$f = "Hello";

  3.5 The concept of variable variables

$AA = "CC";

$CC = "DD";

echo $ $AA; Variable variable

$DD = & $aa; & Take Address

$DD = "ee";

Echo $aa;

4, operator, expression

Relational operators: +-*/% + +--+ = =

      Number + string = number

string + string = 0

Integer/integer = may be decimal

Comparison operators:> < >= <= = = =!

Logical operators: and && or | | !

echo @ $c; The error suppressor @ does not suppress all

5. Statements

Branch:...

Cycle:...

6. Functions

  <?php

Four elements: return type, function name, argument list, function body

 1. The simplest way to define

function Show () {

echo "Hello";

}

2. function definition with parameters

function Show ($a) {

echo $a;

}

3. function definition with default value, no parameter added, output default value

function Show ($a = "mydb") {

echo $a;

}

 4. function definition with return value, string added to 0

function Show ($a, $b) {

return $a + $b;

}

 5. The function definition of the variable parameter, similar to the method overload in C #, the method name is the same, the parameter type, the number is different

function Show () {

$attr = Func_get_args ();//Gets the parameter passed in by the user, returns the array

$count = Func_num_args ();//Gets the number of arguments passed in

Define a variable, store and

$sum = 0;
for ($i =0; $i < $count; $i + +) {
$sum = $sum + $attr [$i];
}
return $sum;
}

Echo Show (+/-);

?>

Getting Started with PHP

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.