Php--each and List usage list for each safe each list as value I JS traverse List collection EAC

Source: Internet
Author: User
Usage of 1.each
Look at the API first
Array each (array & $array)
This is described in the API: each-returns the current key/value pair in the array and moves the array pointer forward one step
Let's take a look at what the returned array looks like.

 !--? php  $arr  =  array  ( ' You ' ,  ' if ' ,  ' ann ' ,  ' good ' ,  ' ,  ' is ' ,  ' Sunny ' ,  ' Day ' ;p rint_r (  $arr )); Print_r (each ( $arr ));  Echo   '  ' ; /* Returns an array ([1] = = You [value] = you [0] = 0 [key] = 0) Array ([1] = = if [value] = if [0] = 1 [key] + 1) */ //execute the same piece of code, from ' You ' to ' if ', stating that each is executed once, the cursor moves to the end of the array  //0 and key is the key  //1 and value holds the value  //So each satisfies the traversal of the array, gets the current key and value, and each time it executes, moves the trailing cursor to the tail  // So the loop array can also be written with each  reset ( $arr );  for  (;  $tmp  =each ( $arr );) { echo   $tmp  [ 0 ],  ' ~ ' ,  $tmp  [ 1 ],  ' 
' ;} /* Return 0~ you 1~ if 2~ ann 3~ good 4~ then 5~ is 6~ sunny 7~ Day */ ?

Usage of 2.list
Let's see what the API says.
Like Array (), this is not a real function, but a language structure. List () assigns a set of variables in one-step operation.
Take a look at an example:


   
    list($a,$b)=array(10,20);echo$a,'~',$b,'
';//返回10~20?>

Yes, you can assign values to a set of variables.
Let's look at another example:


   
    list($a,$b,,$c)=array(2=>10,3=>20,4=>30,1=>40);echo$a,'~',$b,'~',$c,'
';//返回notice~40~20//执行到$a的时候返回给我一个notice:说数组没有0键?>

According to the general idea should return: 10~20~40
Why did you return to this notice~40~20?
A: This involves the operation of the list, the list is so assigned
First: Do not tube to the right of the array, see the list of variables, from left to right should be a=aRr[0] B=ARR[1] C=aRR[3]thenafter:fromRightto theleftOpenStartFuvalue,Fuvalueof theShunOrderis a C=ARR[3] b=aRr[1] A=ARR[0]
So c= b = 40 because there is no arr[0], so $ A has given a warning
3. Iterating through arrays with each and list


   
    $arr = array('你','若','安','好','便','是','晴','天');for(;list($k,$v)=each($arr);){    echo$k,'~',$v,'
';}/*return:0~你1~若2~安3~好4~便5~是6~晴7~天*/?>

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the use of Php--each and list, including the each,list aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.