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) ;}?>
<? 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. '';}}?>
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.