Mobile app Interface Programming Technology-PHP advanced array for learning and implementation, app advanced

Source: Internet
Author: User

Mobile app Interface Programming Technology-PHP advanced array for learning and implementation, app advanced

  • Array creation and initialization
<? Php // create an array variable arr and try to create an index array/*** create without an initial value. then assign the value * Note: the subscript must be an integer */$ arr = array (); $ arr [0] = 'bound'; $ arr [1] = 'boundary '; if (isset ($ arr) {print_r ($ arr);}/*** create with initial value * // double quotation marks or single quotation marks are available, the array starts from 0 $ arr2 = array ("boss", 'kid'); if (isset ($ arr2) {print_r ($ arr2 );} // The key is on the left, and the key value $ arr3 = array ('0' => 'bound', '2' => 'old 3 ', '1' => 'kid'); if (isset ($ arr3) {print_r ($ arr3) ;}?>
  • Use the array value
<? Php // from the array variable $ arr, read the value of the key 0 $ arr = array ('bound', 'two '); // $ arr0 = $ arr ['0']; $ arr0 = $ arr [0]; if (isset ($ arr0) {print_r ($ arr0) ;}?>
  • Print the data of the array
// Access through index directly <? Php $ arr = array ('zhang san', 'Li si', 'wang 2'); for ($ I = 0; $ I <3; $ I ++) {echo $ arr [$ I]. '<br>' ;}?>
// Use foreach to loop the values in the number group <? Php $ arr = array ('I' => "I", 'love' => 'ai', 'U' => 'you '); if (isset ($ arr) {foreach ($ arr as $ key => $ value) {echo $ value. '';}}?>
  • Summary

    PHP array is dividedIndex Array Join Array

The associated array is an array where the key value is a string.

For example, the foreach example in the previous example.

<? Php $ arr = array ('Wo '=> "I", 'love' => 'love', 'lil' => 'lil '); if (isset ($ arr) {foreach ($ arr as $ key = >$ value) {print_r ($ value); // echo $ value ;}}?>
  • Create and initialize associated Arrays
<? Php // $ arr = array ('apple' => 'apple'); $ arr = array (); $ arr ['apple'] = 'apple '; if (isset ($ arr) {print_r ($ arr) ;}?>
  • Join array reference (use the name of the array variable followed by brackets + keys to access the values in the array. The key is enclosed by single quotation marks or double quotation marks .)
<? Php $ arr = array ('apple' => "apple", 'bana' => "banana", 'pineapple' => "pineapple "); $ arr0 = $ arr ['apple']; if (isset ($ arr0) {print_r ($ arr0) ;}?>

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.