JavaScript arrays and PHP array traversal comparison Introduction

Source: Internet
Author: User
Tags javascript array

Both the Javascripe and PHP arrays are of type map, that is, the key value type is not limited. Here I compare the way the two arrays are traversed:
The 1:javascript array traversal uses the in operator, for example, key in Arr, where key is assigned the key in the ARR array and gets value through Arr[key].

    forin arr){        console.log("arr[""] = " + arr[key]);    }

The 2:php array is the use of the as operator, and direct $arr as $k + $v can be used during traversal to place key and value respectively into $k and $V variable.

    $arrarray("k1":"v1","k2":2);    for($arras$k=>$v){        echo$k" = "$v"<br/>";    }

JavaScript arrays and PHP array traversal comparison Introduction

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.