A summary of the basics of PHP for beginners to learn how to create dynamic web pages

Source: Internet
Author: User
After reading some basic PHP knowledge, I will summarize it here: 1. there are three measures for Embedding PHP scripts in HTML: <scriptlanguage = "php"> // method 1 echo ("test \"); </script> <? // Embedded method 2 echo "<br> test2";?> <? Php // embedded

After reading some basic PHP knowledge, I will summarize it here:

 1. there are three measures for Embedding PHP scripts in HTML:

<Scriptlanguage = 'php'>
// Embedded method 1
Echo ('test \');
</Script>
<?
// Method 2
Echo '<br> test2 ';
?>
<? Php
// Embedded method 3
Echo '<br> test3 ';
?>

There is also an embedded method, that is, the application and Asp mark similar <%>, but to modify the PHP. ini coherent configuration, it is not recommended to apply.

  2. PHP comments are divided into single-line and multi-line comments, which are the same as java comments.

<?
// Here is a single line comment
Echo 'test ';
/*
Here is a multi-line comment! Many lines of comments can be written.
*/
?>

Be careful not to include nested comments, such as/* aaaa/* asdfa */asdfasdfas */. such comments will display titles.

  3. PHP has five important data types: integer, double, string, array, and object.

  4. to call external variables in a function, you must declare them using global. Otherwise, you cannot visit them. this is a difference between PHP and other programming languages. Example code:

<?
$ A = 1;
Functiontest (){
Echo $;
}
Test (); // the result "1" cannot be output here ".
Functiontest2 (){
Global $;
Echo $;
}
Test2 (); // You can output the result "1 ".
?>

Note: PHP can declare static variables within the function. It is used in the same C language.

 5. variables and functions of variables

<?
// Variable
$ A = 'hello ';
$ A = 'world ';
Echo '$ a $ hello'; // output 'helloworld'
Echo '$ a $ {$ a}'; // the same output is 'helloworld'
?>
<?
// Variable functions
Functionfunc_1 (){
Print ('test ');
}
Functionfun ($ callback ){
$ Callback ();
}
Fun ('func _ 1'); // This will output 'test'
?>

  6. PHP supports both scalar arrays and associated arrays. you can use list () and array () to create arrays. the array subscript starts from 0. For example:

<?
$ A [0] = 'abc ';
$ A [1] = 'Def ';
$ B ['foo'] = 13;
$ A [] = 'hello'; // $ a [2] = 'Hello'
$ A [] = 'world'; // $ a [3] = 'world'
$ Name [] = 'Jill'; // $ name [0] = 'Jill'
$ Name [] = 'Jack'; // $ name [1] = 'Jack'
?>

  7. join parameter transfer (& application), two methods. Example:

<?
// Method 1:
Functionfoo (& $ bar ){
$ Bar. = 'andsomethingexist ';
}
$ Str = 'thisastring ,';
Foo ($ str );
Echo $ str; // output: ThisisaString, andsomethingextra
Echo '<br> ';
// Method 2:
Functionfoo1 ($ bar ){
$ Bar. = 'andsomethingexist ';
}
$ Str = 'thisastring ,';
Foo1 ($ str );
Echo $ str; // output: ThisisaString,
Echo '<br> ';
Foo1 (& $ str );
Echo $ str; // output: ThisisaString, andsomethingextra
?>

  8. default function value. The default value of function support in PHP is the same as that of C.

<?
Functionmakecoffee ($ type = 'coffee '){
Echo '*** acupof $ type. \ n ';
}
Echomakecoffee (); // '*** acupofcoffee'
Echomakecoffee ('Espresso '); //' *** acupofespresso'

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.