PHP basic Syntax chapter II _php Tutorial

Source: Internet
Author: User
One, how to define a constant

Keyword: Define syntax define (' Constant name ', ' constant value ')

Two, array

1 Defining an array

The keyword array Syntax array (KEY=>VALUE,KEY2=>VALUE2,KEY3=>VALUE3) key can be an integer or string, value can be any value

' Bar ', 123=>true); echo $arr [' too ']. '
'; echo $arr [123];?>

Method of printing an array print_r keyword: print_r syntax print_r (to print group name), mainly for debugging

' 10010 ', ' stu_name ' = ' Lao Zhao '; Print_r ($stu);?> output result Array ([stu_no] = 10010 [Stu_name] = Lao Zhao)

Output method echo $ array name [key]

' 10010 ', ' stu_name ' = ' Lao Zhao '; echo $stu [' stu_no ']. '
'; echo $stu [' stu_name '];?> output results

10010

Lao Zhao

Another way to define an array is to directly enter the value values key for shaping from 0

Array (' value ', ' value2 ', ' value3 ', ' value4 ')

The output is an array ([0] = phi [1] = Lele [2] = = Pope [3] = (Lao Zhao)

Output separately:

'; echo $stu [1]. '
'; Echo $stu [2]. '
'; Echo $stu [3]. '
';?> output results

Del piero

Lele

Pope

Lao Zhao

Loop output method for statement syntax

for (cyclic condition) Example: $i =0; $i <4; $i + +

{

echo $ array name [loop variable name]

}

'; }?> Output Results

Del piero

Lele

Pope

Lao Zhao

While loop syntax

$ condition Variable name = condition Variable Value

while (conditional statement) example $i<4

{

$ array name [$ condition variable name];

$ conditional Variable + +

}

Output results Skin Pile Pope Lao Zhao

Add an element at the end of an array

Syntax $ array name =ARRAY[VALUE,VALUE1,VALUE2,VALUE3];

$ array name []= the value to add;

$ array name []= the value to add;

Output results skin Pile Pope old Chao Haomin Scottish Lu Teng

Create a range of array range and count methods to get how many elements are in the array

Syntax $ array name =range (range start, Range end)

Count ($ array name)

Output 1 2 3 4 5 6 7 8 9 10 11 12

Output result a b c d e F g h i j k l m n o p q R S t u v w x y Z

Three-padding array

Array_pad

Grammar

Array_pad ($ array name, array length, padding default value)

Output 0 1 2 3 0 0 0

Five, delete and insert replacement elements in the array array_splice

Array_splice two parameters for delete four parameters for insert or replace (the third parameter is 0 when inserting, not 0 is replaced)

Delete Syntax Array_splice ($ array name, delete end subscript) subscript equals Delete before this key

Output 5 6 7 8 9 10 11 12

Insert Syntax Array_splice ($ is inserted array name, subscript, 0,$ Insert new array name) subscript to insert a new array before this subscript to the previous

Output 0 1 2 3 4 a B C 5 6 7 8 9 10 11 12

Replace syntax Array_splice ($ replaced by array name, key,key2,$ Replace with new array name) Subscript 1 Subscript 2 is combined to represent the number of subscripts starting from subscript key key2 elements are replaced by a new array

Output is 0 1 2 a b C 9 10 11 12

Starting from 3, the number of 6 elements is replaced with a,b,c

This article is from the "PHP Learning Notes" blog

http://www.bkjia.com/PHPjc/478717.html www.bkjia.com true http://www.bkjia.com/PHPjc/478717.html techarticle one, how to define a constant keyword: Define syntax define (constant name, constant value)? $a =123; define (I, $a); Echo I;? Two, array 1 defines an array of keywords array syntax array (key ...

  • 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.