PHP Array (prev) traversal

Source: Internet
Author: User
 Demo = Array (0=> ' apple ',1=> ' orange ',2=> ' banana '); * 2, associative array: Key-value form * 3, Multidimensional array: array of arrays $demo = Array (array (), array ()); *//* * Array Traversal * 1, for * This way is not preferred * array must be subscript contiguous indexed array * * 2, foreach * foreach ($arr as $item) {...} * foreach ($ar r as $key = = $val) {...} * * 3, while () list () every () combination * each (): requires an array as a parameter, returns array (0,1, $key, $val), is a cursor operation, executes to the last return False * List (): A, list () = array () needs to be assigned to list () * B, the number of elements in the array is the same as the number of parameters in the list () function * C, each element in the array Assign to each parameter in list () * d, List () can only accept indexed array * E, traverse by index in subscript order * * Array internal pointer control function * * PREV ($arr): Previous reference    Pin * Next ($arr): Next pointer * Reset ($ARR): First * END ($arr): Last * * Current ($arr): currently key * Key ($arr): Current value * *///Forecho "\ n for ... \ n"; $demo = Array (' Apple ', ' orange ', ' banana '); for ($i =0; $i
 
  ' Apple ',1=> ' orange ',2=> ' banana '); for ($i =0; $i
  
   
 $val) {echo '. $key. ' = '. $val. ';} echo "\ n". ' ----------------------------------------'; $user = array (' ID ' =>1, ' name ' = ' Jack ', ' age ' =>10, ' sex ' = '    Male ');//Whileecho "\ n" while ($arr =each ($user)) {//"$arr [0]--> $arr [1]"; echo $arr [' key ']. -". $arr [' value '].";} echo "\ n-------------------------------------------", while (list ($key, $value) =each ($user)) {echo '. $key. '----- > '. $value. ';} echo "\ n-------------------------------------------\ n", Reset ($user), while (List ($key, $value) =each ($user)) {echo ' . $key. '-----> ' $value. ';} echo "\ n-------------------------------------------\ n" while (list ($key, $value) =each ($user)) {echo '. $key. '----- > '. $value. ';} Reset ($user); next ($user); next ($user); echo "\ n-------------------------------------------\ n"; while (List ($key, $ Value) {=each ($user)) {echo '. $key. '-----> ' $value. ';} Reset ($user); echo "\ n"; Echo current ($user). ' ----------> '. Key ($user). " \ n "; end ($user); Echo Current ($USER). ' ----------> '. Key ($user). " \ n ";p rev ($user); Echo current ($user). ' ----------> '. Key ($user). " \ * * * result * for ... apple orange Banana for ... apple orange Banana foreach ... apple orange banana foreach ...  0=>apple 1=>orange 2=>banana----------------------------------------while ... id-->1 name-->jack Age-->10 sex-->  Male--------------------------------------------------------------------------------------ID----->1 Name----->jack Age----->10 Sex----->  Male--------------------------------------------------------------------------------------Age----->10 Sex----->male1---------->idmale---------->sex10---------->age */
  
 
  • 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.