PHP Base _ Variables and comparators

Source: Internet
Author: User
Tags php and mysql

I PHP rookie a, first read "PHP and MySQL Web development", the comparison of some of the basic things listed, convenient and their own rookie quick start, and easy to review their understanding later.

① variable

1. The characteristic should be that the variable does not need to be predefined and can be used directly.

2. The effect of variables placed in single and double quotes is completely different.

1 <? PHP 2         ' myString ' ; 3         ' $test.------ ' ; 4         " $test.------ " ; 5 ?>

The results are shown below

  

  Conclusion: Variables can be identified in double quotation marks and can only be used as strings within single quotes

3. String connection with ". ($aaa = $bbb. $CCC)

4. Constants (part of a variable)

A significant difference in the definition of constants and variables is the use of the "$" notation

For example

Define (' AAA ', ' astring ')//constant

$AAA = ' astring ' //variable

② comparison Symbols

1.== (equivalent)

Description

Variables: values are equal.

Array: Contains the same elements.

1<?PHP2$test 1 ='111';3$test 2 =111;4$test 3 = Array (111,222,333);5$test 4 = Array ('222','111','333');6$test 5 = Array ('test1'='111','test2'='222','test3'='333');7$test 6 = Array ('test1'=111,'test2'=222,'test3'=333);8         if($test 1== $test 2) {Echo'Success1';}9         if($test 3== $test 4) {Echo'Success2';}Ten         if($test 5== $test 6) {Echo'SUCCESS3';} One?>

Output Result: SUCCESS1SUCCESS3

2.=== (Identity)

Variables: Both numeric and data types are equal

Arrays: containing the same order and type

<?PHP $test 1='111'; $test 2=111; $test 3= Array (111,222,333); $test 4= Array ('111','222','333'); $test 5= Array ('test1'='111','test2'='222','test3'='333'); $test 6= Array ('test1'=111,'test2'=222,'test3'=333); $test 7= Array ('test3'='333','test2'='222','test1'='111'); $test 8= Array ('test1'='111','test2'='222','test3'='333'); if($test 1=== $test 2) {Echo'Success1';} if($test 3=== $test 4) {Echo'Success2';} if($test 5=== $test 6) {Echo'SUCCESS3';} if($test 5=== $test 7) {Echo'SUCCESS4';} if($test 5=== $test 8) {Echo'SUCCESS5';}?>

Output Result: SUCCESS5

3.0 and not 0

Not 0 is true,0 to False

<? PHP         ' 0 ' ;         1 ;         if ' Success1 ' ;}         if ' Success2 ' ;}? >

Output: Success2 ( in the use = = to make sure to remember not to write less equal sign, written $test1 = ' 0 ')

③ structure

1. Branches (no spaces between ElseIf)

Ifelse  {}

    

  

PHP Base _ Variables and comparators

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.