PHP half way home (1)

Source: Internet
Author: User

Finally, the environment has been configured. Try PHP!

 

Where can I write the code?
<? Php code?>

<? Code?>

<% Code %>

<Script language = "php"> code </script?>

 

Mark the author. Why comment?
// Author: matter

/*

* Author: matter

*/

# Author: matter

 

Finally officially started. OK, go directly to the classic case
<? Php echo 'Goodbye world ~ ';?>

<? Php echo "Goodbye world ~ ";?>

<? Php print "Goodbye world";?>

<? Php printf ("Goodbye World");?>

Pay attention to the color-changing part.

Single quotation marks are acceptable. Double quotation marks are also acceptable.
The support for escape characters in single quotes is incomplete!
Echo works, print works, and printf works.
Why is printf in parentheses?
The parentheses of echo () and print () can be omitted.
Is echo different from print?
Echo () has no return value. print () successfully outputs 1
It can be seen that echo () is faster than print!
Use printf for dynamic text, and echo for static text
$ Test = Sprint ("$ %. 2f", 12.3424 );

Printf ("Goodbye -- World, $ test ");

Sprintf can assign values to variables ~

 

It's time to let me see the variables!
Weak language-everything is scalar (scalar)

$ MyVar = "anything ";

Array

$ Arr [0] = "abc ";

 

It's time to see the object!
Class MyTest {

Private $;

Public function getA (){

Return $ this->;

}

Public function setA ($ ){

$ This-> a = $;

}

}

$ Useage = new MyTest ();

$ Useage-> setA ("HI ~ ");

Echo $ useage-> getA ();

Feel it for me and JAVA

No function return type
Call methods and properties with "->" instead "."
Whether or not it is declared or not, add $ to the variable
 

I don't know what type the variable is. What should I do?
Forced conversion

(Array) $ fig

Automatic conversion

The preceding number is used for string calculation.
The If () condition determines that the calculation result is not 0.
 

I want to have the right to know and control the variable type!
String Gettype (mixed var );
Returns the type of the variable var.

Boolean settype (mixed var, string type)
Type of the conversion variable

 

How many variables are responsible?
GLOBAL $ var; // GLOBAL variable
STATIC $ var; // STATIC variable
Currently, the keywords are not the same. Other keywords are normal.

Super global variable-predefined, environment-related
$ _ SERVER, $ _ GET, $ _ POST, $ _ COOKIE

$ _ FILES, $ _ ENV

 

When the variable remains the same ~
Define ("PI", 3.1415 );

 

Operator, operand, control statement
New: AND OR NOT XOR

Others are not found at the moment...


 

From matter605924657

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.