1. Traversing array knowledge

Source: Internet
Author: User
Tags array definition

1<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>5<title> Untitled Document </title>67 8<body>9 Ten<form action= "0320test1.php" method= "POST" > One<input type= "text" name= "txt"/> A<input type= "Submit" Name= "BTN" value= "Submit"/> -</form> -  the<?PHP -      -     //Array Definition - //definitions in different ways, the array can put any type of data + //index array definition: - //$attr = Array (1,2,3,4, "AA"); + //print_r ($attr); A //definition of associative array: at     $attr=Array("One" =>10, "2" = "AA", "three" =>20); -     //Print_r ($attr); - //echo $attr [2]; -      - //Array traversal - //for loop traversal, for indexed arrays, cannot traverse associative arrays in     /*For ($i =0; $i <count ($attr); $i + +) -     { to echo $attr [$i]. " <br> "; +     }*/ -      the     //foreach traversal, which iterates through indexed arrays and associative arrays *     /*foreach ($attr as $value) $     {Panax Notoginseng echo $value. " <br> "; -     }*/ the      +     /*foreach ($attr as $key = $value) A     { the echo $key. " = ". $value." <br> "; +     }*/ -      $      $     //each () function, take an element inside the array, take the value down, and return the element as an array -     /*Print_r (each ($attr)); - echo "<br>"; the Print_r (each ($attr)); - echo "<br>";Wuyi Print_r (each ($attr)); the echo "<br>--------------------------"; - //Reset the pointer, point to the first element Wu Reset ($attr); - Print_r (each ($attr)); About echo "<br>"; $ Print_r (each ($attr)); - echo "<br>"; - Print_r (each ($attr));*/ -      A     //list () function +     /*list ($a, $b, $c, $e, $f) = $attr; the echo $a; - echo $b; $ echo $c; the echo $e; the echo $f;*/ the      the     //using the each () and list () functions to iterate through an array, an indexed array and an associative array can be -     /*list ($key, $value) = each ($attr); in echo $key. " = ". $value; the list ($key, $value) = each ($attr); the echo $key. " = ". $value;*/ About /*     the while (list ($key, $value) = each ($attr)) the     { the echo $key. " = ". $value." <br> "; +     }*/ -      the     //PointersBayi     /*Echo current ($attr);//Take the content pointed to by the present pointer value the Echo Key ($attr);//Take the index pointed to by the current pointer key the echo "<br>"; - Next ($attr);//move the pointer down - Echo current ($attr);//Take the content pointed to by the present pointer value the Echo Key ($attr);//Take the index pointed to by the current pointer key the echo "<br>"; the prev ($attr);//move the pointer up the Echo current ($attr);//Take the content pointed to by the present pointer value - Echo Key ($attr);//Take the index pointed to by the current pointer key the echo "<br>"; the End ($attr);//point pointer to last element the Echo current ($attr);//Take the content pointed to by the present pointer value94 Echo Key ($attr);//Take the index pointed to by the current pointer key the echo "<br>"; the Reset ($attr);//Reset the pointer the Echo current ($attr);//Take the content pointed to by the present pointer value98 Echo Key ($attr);//Take the index pointed to by the current pointer key About echo "<br>";*/ -     101     /* Do102     {103 Echo Key ($attr);104 Echo current ($attr); the echo "<br>";106     }107 While (Next ($attr))*/108     109      the     //pre-defined arrays111 //print_r ($_server); the //var_dump ($_env);113      the      the?> the</body>117118     119     

1. Traversing array knowledge

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.