PHP Basic Syntax

Source: Internet
Author: User
Tags php definition

1. Tags and annotations

<?php

Code

?>

Use the/* */Comment

2. Output statements

echo "Hello", "World"; echo can output multiple strings, separated by commas

print "Hello"; Print can only output one string

3. Data type

PHP is a weakly typed language

Data types can be converted automatically

4. Variable definition

PHP definition variables start with $

$a = 5;

$b = "Hello";

Variable variable:

* $a = "Hello";
$hello = "World";
echo $ $a; Output World

Determine if the variable is defined:

$a = 3;

echo isset ($a); True returns 1, FALSE returns 0

To clear a variable:

unset ($a);

Determine if the variable is empty:

Empty ($a)

Take address:

$a = 5;
$b =& $a; & Take addresses, A and B take the same address in memory, change one, and the other changes
$b = 10;
echo $a; Output 10
Unset ($b); Simply cancels the value association, the referenced variable does not disappear
echo $a; Output 10
Echo $b;

5. Type conversion

$a = 5;
Var_dump ($a); Output variable Details
$b = (string) $a; Type conversions
Var_dump ($b);

6. Operator expressions

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

$a = 10;
$b = 3;
echo $a/$b; Output 3.33333333333

String: stitching string with dot not with +

echo "Hello". " World ";

Comparison operator: < > <= >== = = =!

Logical operators: and && or | | !

Error control Operator: @

echo @ $a; Can mask errors

Ternary operator:? :

echo true? " Male ": ' Female ';

PHP Basic Syntax

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.