PHP Learning Note 1

Source: Internet
Author: User

PHP Output Information:

<? PHP      " Hello me " ;? >

PHP gets the client's request, $_post, $_get, respectively, to get the POST and get requests from the client browser:

<? php    echo $_post["Age";    echo $_get["name"];? >

Forced conversion type, same as Java and C language

<? PHP     = $_get["name"];    Echo (int) $a;? >

Double quotes and single quotes are different, double quotation marks inside the PHP variable will be parsed, single quotation marks inside the PHP variable is not parsed, the following example will output: 3234abc 3234$a;

<? PHP     = $_get["name"];     " 3234$a<br> " ;     ' 3234$a ' ;? >

Basic Types in PHP

Primitive Type Boolean string integer float Complex Type array Object Special Type Rsourcenull

Boolean type value: TRUE, FALSE (case insensitive)

Integer: Decimal, hexadecimal (beginning with 0X), octal (0-based)

Get the variable type GetType (*), the following example output is, string integer:

<? PHP     = $_get["name"];    Echo GetType ($a);     = (int) $a;     " <br> " . GetType ($b);? >

Judging data types: Is_bool (), Is_int (), Is_integer (), Is_float (), Is_real (), Is_object (), and Is_array ()

<? PHP     = $_get["Age"];     = (int) $a;     if (is_string ($a)) {        'string <br>';    }     if (Is_int ($b)) {        'number';    }? >

Use echo to output an array object directly:

<? PHP     = Array (        "foo""bar",        "  bar""foo",    );    Echo $array. " <br> " ;    echo Json_encode ($array);? >

To output an array directly using Print_r:

<? PHP     = Array (2,2,3,4,5,,2,2);    Print_r ($array);? >

ECHO is a PHP statement, print and Print_r are functions, the statement does not return a value, the function can have a return value (even if it is not used)

Print only prints out values for simple type variables (such as int,string)

Print_r can print out values for complex type variables (such as arrays, objects)

Through $array[b] and {$array [' B ']};

<? PHP     = Array ("a"= =1"b"=2" 3 " );    Print_r ($array);     " {$array [' B ']}999<br> " ;     " $array [b]9999 " ;? >

Delete the array:

<? PHP     = Array ("a"= =1"b"=2" 3 " );    Print_r ($array);     " {$array [' B ']}999<br> " ;     " $array [b]9999 " ;? >

The Foreach loop, the Loop object, the following case will output: 12345

<?PHP $array= Array ("a"=1,"b"=2,"3","C"=4,"DD"=5); foreach($array as$val)    {echo $val; }?>

While loop, loop the key and value values:

<?PHP $array= Array ("a"=1,"b"=2,"3","C"=4,"DD"=5);  while(List ($key) =Each ($array))        {echo $key;        echo $array [$key]; Echo"<br>"; }?>

For loop:

<?PHP $array= Array ("0"=1,"1"=2,"3","3"=4,"4"=5);  for($i =0; $i < count ($array); $i + +) {echo $i."="; echo $array [$i]."<br>"; }?>

Class, Create a class, and call the method of this class, new out of the instance is a pointer to the C language pointer call method: :

<? PHP     class foo{        function dof () {            "Foo";        }    }     New Foo;    $f, DOF ();? >

Eof

PHP Learning Note 1

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.