PHP Learning Note Nine "array two"

Source: Internet
Author: User

<! DOCTYPE HTML Public"-//w3c//dtd HTML 4.01 frameset//en" "Http://www.w3.org/TR/html4/frameset.dtd" >PHP$arr[0]=1; $arr[1]= "Hello World"; $arr[2]=true; $arr[3]=45.45; //the value of the PHP array can be any type of   for($i= 0;$i<Count($arr);$i++)  {   Echo"<br/>".$arr[$i]; }    //the second way of the array  Echo' <br/> the second way to create an array '; $arr 1=Array(1, "Hello World", 23.4,false);  for($j= 0;$j<Count($arr 1);$j++)  {    Echo"<br>".$arr 1[$j]; }    //the third way of the array is to specify key, by default the key is 0  $arr 2["Test1"]= "Hello"; $arr 2["Test2"]= "World"; $arr 2["Num"]= "34";  for($z= 0;$z<Count($arr 2);$z++)  {    Echo"<br/>".$arr 2[$z];//when you specify a key, you cannot traverse it in this way, only with foreach convenience  }  Echo"<br/> cannot traverse with for, only use foreach"; //foreach uses a wider range of essays  foreach($arr 2  as $val)  {   Echo"<br/>".$val; }    Echo"<br/>". Output Key "; foreach($arr 2  as $key=$val)  {   Echo"<br/>".$key." =".$val." <br/> "; }    //*********************  $arr 3[true]= "Hello";//If you use True as key then you need to access $arr 3[1]  $arr 3[false]= "World";//If you use false as key then Access $arr 3[0]  $arr 3[NULL]= "Beijing";//If you use NULL as key, you can use null and "" to access $arr3[null] or $arr 3[""];  Echo"<br/> access an array of true,false,null as key"; Echo $arr 3[NULL]; Echo $arr 3[""]; //*********************   $arr 4[123.4]= "Hello World"; Echo"<br/>".$arr 4[123.4]; Echo"<br/>".$arr 4[123]; Echo"<br/>"; Print_r($arr 4);//print_r output Array information    Echo"<br/>"; Var_dump($arr 4);//var_dump can output array information in more detail//*********************   Echo"The array of <br/>php is dynamically growing"; $arr 5=Array(2,3); $arr 5[2]= "Hello World"; $arr 5[5]= "Beijing";//this array will not error, but 3,4 no use, but not through $arr5[3] to access   foreach($arr 5  as $val)   {    Echo"<br/>".$val; }  //******************** to determine if it is an array  Echo"<br/>"; $arr 6=Array(23,56); $b=4; Echo Is_array($arr 6); Echo"<br/>".Is_array($b); //******************** splitting a string explode returning an array  $str= "Beijing & Shunping & Tianjin & Song Jiang"; $arr 7=Explode("&",$str); Echo"<br/>".Var_dump($arr 7)." Element has ".Count($arr 7); //Example  Echo"<br/>"; $colors=Array("Red", "Blue", "green", "yellow");  for($i= 0;$i<Count($colors);$i++) {    Echo"<br/>".$colors[$i]; } //using while traversal $i= 0;//Cyclic control Variables    while($i<Count($colors))    {        Echo"<br/>".$colors[$i]; $i++; }  // Do While $i=0; Do{   Echo"<br/>".$colors[$i]; $i++; } while($i<Count($colors)); //foreach Traversal foreach($colors  as $key=$val) {   Echo"<br>".$key." =".$val; } //**********unset releases a variable that uses the method to delete the element completely  $arr 8[0]=123; $arr 8[1]=345; $arr 8[2]= "Hello World"; unset($arr 8[1]); foreach($arr 8  as $val) {   Echo"<br/>".$val; } //If we create an array, we do not assign a subscript to an element,//Then PHP will use the current largest subscript value plus 1 as the subscript for that element. Echo"<br/>"; $arr=Array(5=> "logo", 567,90); $arr[5]= "yes";//Modifying the value of an array element can be modified directly by the index Echo $arr[5]; Echo"<br/>".$arr[6]; Echo"<br/>".$arr[7]; //Array Traps $arr[bar]= "Hello World";//No quotation marks are equivalent to bar being a constant, so that a fatal error may occur Echo"<br/>".$arr[bar];//array operator + means union two elements (will remove the same key on the right) $a=Array("A" and "Apple", "b" = "Bannana"); $b=Array("a" = "pear", "b" = "Strawberry", "C" and "Cherry"); $c=$a+$b; Echo"\ $a +\ $b result <br/>"; Var_dump($c); $c=$b+$a; Echo"\ $b +\ $a result <br/>"; Var_dump($c);?>

PHP Learning Note Nine "array two"

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.