Basic operations on PHP arrays and classic operation instances for Traversing arrays, basic operations on Arrays

Source: Internet
Author: User

Basic operations on PHP arrays and classic operation instances for Traversing arrays, basic operations on Arrays

The instance is as follows:

<? Php Index array // array first definition $ arr = array (, 3); var_dump ($ arr); // array second definition $ arr = [, 3]; var_dump ($ arr); // The third definition of the array $ arr [0] = 7; $ arr [1] = "hello"; var_dump ($ arr ); echo $ arr [2]; // value Association array $ arr = array ("name" => "Lee", "sex" => "female ", "age" => "20"); echo $ arr ["sex"]; traversal array // for Loop traversal applies to index arrays $ arr =, 8]; for ($ I = 0; $ I <count ($ arr); $ I ++) {echo $ arr [$ I]. '<br>' ;}; // foreach loop traversal applies to indexes and associated arrays $ arr = array ("name" => "Xiao Li ", "sex" => "female", "age" => "20"); foreach ($ arr as $ k => $ v) {// echo $ k. ':'. $ v. '<br>'; echo "{$ k }:{ $ v} <br>" ;}; $ arr = [, 8]; foreach ($ arr as $ k) {echo $ k. '<br>' ;}; $ arr = array ("name" => "Lee", "sex" => "female ", "age" => "20"); var_dump (each ($ arr); list ($ a, $ B) = array (name, Xiao Li ); echo "{$ a}, {$ B}"; list and each combine to traverse/* $ arr = array ("name" => "Xiao Li ", "sex" => "female", "age" => "20"); while (list ($ k, $ v) = each ($ arr )) {echo "{$ k }:{$ v} <br>" ;}*/pointer traversal/* $ arr = array ("name" => "Xiao Li ", "sex" => "female", "age" => "20"); echo current ($ arr); // obtain valueecho key ($ arr ); // obtain keynext ($ arr); echo current ($ arr); echo key ($ arr); prev ($ arr); echo current ($ arr ); echo key ($ arr); end ($ arr); echo current ($ arr); echo key ($ arr); reset ($ arr); echo key ($ arr ). ':'. current ($ arr ). '<br> ';*/

The basic operation of the above PHP array and the classic operation instance for traversing the array are all the content shared by the editor. I hope you can give us a reference and support for the help house.

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.