Chapter 1 of basic PHP syntax

Source: Internet
Author: User

 

I. PHP annotation Method

 

1. // (single line comment) 2./**/(multi-line comment) 3. # (mostly for Unix SHELL) 2. Embedding Method

 

You can specify it by yourself. Generally

 

<? Php...?> // Recommended <?...?> <Script language = "php">... </script> <%... %> 3. Reference File

 

Include and require

 

1. include is mostly used in Process Control to simplify the process.

 

Include ("myshortdefile. php") 2. require is often used at the beginning of a program. After being loaded, it becomes part of the program.

 

Require ("MyRequireFile. php") 4. Variables in PHP

 

1. variable name conventions

 

(1) variables in php are case sensitive.

 

(2) The variable name must start with the dollar sign $

 

(3) variable names can start _.

 

(4) variable names cannot start with numbers

 

$ Mystring = "I Am a string"; $ NEWLINE = "NEWLINE"; $ int1 = 38; 5. Data Type

 

1. scalar Data Type

 

(1) boolean

 

<? Php $ foo = true; echo $ foo;?> The output result is 1.

 

 

<? Php $ foo = false; echo $ foo;?> The output result is null.

 

(2) integer

 

<? Php $ int1 = 5; echo $ int1;?> (3) float is also called double

 

<? $ Dou = 123.456; echo $ dou;?> (4) string

 

<? $ Str = "Welcome To BeiJing"; // more than one word uses double quotation marks $ str2 = 'prometheus '; // only one word is enclosed in single quotes $ k = <SQL select * from news where news_id = 10 order by news_id desc SQL; echo $ k. "<br>"; // The Delimiter is used to keep the string format of multiple rows echo $ str. "<br>"; echo $ str2. "<br>";?> Check variable type

 

<? $ Str = "Welcome To BeiJing"; // more than one word uses double quotation marks $ str2 = 'prometheus '; // only one word is enclosed in single quotes $ k = <SQL select * from news where news_id = 10 order by news_id desc SQL; var_dump ($ k ). "<br>"; // The Delimiter is used to keep the format var_dump ($ str) of strings of multiple rows ). "<br>"; var_dump ($ str2 ). "<br>"; $ int1 = 5; var_dump ($ int1 ). "<br>"; $ dou = 123.456; var_dump ($ dou ). "<br>";?> Global variable scope

 

 

 

<? $ A = 10; $ B = 20; function test () {global $ a, $ B;/* defines $ a and $ B as global variables to function TEST, if no global variable is defined, 0 */echo $ a + $ B;} echo test ();?> 2. Composite data types

 

(1) array

 

(2) object

 

3. Special Data Types

 

(1) resource

 

(2) NULL

 

This article is from the "PHP Study Notes" blog

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.