Introduction to PHP Learning point five about PHP array of several basic operations _php Foundation

Source: Internet
Author: User
Tags array definition
Copy Code code as follows:

<?php
/*
* Simple array definition and access
*/
echo "simple array definition and access <br>";
echo "############################################################<br>";
$address =array (5);
$address [0]= "Fuzhou";
$address [1]= "Xiamen";
$address [2]= "Zhangzhou";
$address [3]= "Quanzhou";
$address [4]= "Ningde";
$address [5]= "Nanping";
$address [6]= "Longyan";
echo "I now live in $address[1]<br>";
echo "############################################################<br><br><br>";
/*
* Array Traversal
*/
echo "Array traversal via a For loop <br>";
echo "############################################################<br>";
for ($index =0; $index <count ($address); $index + +) {
Print ("The first in the array", $index. " Regional $address[$index] for <br> ");
}
echo "############################################################<br><br><br>";
/*
* Array Initialization
*/
echo array initialization, and through the date function to get the current month's number, output related array subscript content <br> ";
echo "############################################################<br>";
$arrMonth =array ("January", "February", "March", "April", "may", "June", "July", "August", "September", "October", " November "," December ");
Date_default_timezone_set ("UTC"); Set the default time zone
$month =date ("M");
echo "Array structure";
Print_r ($arrMonth);
Echo "is currently the first". $month. " Month, his English is ". $arrMonth [$month-1]." <br> ";
echo "############################################################<br><br><br>";
/*
* Array initialization, define keys, and then access the array by key value
*/
Echo array initialization, define keys, and then access array <br> via key;
echo "############################################################<br>";
$arrMonth =array ("=>" "January", "Feb" => "February", "Mar" => "March", "APR" => "April", "may" => "may", " June "=>" June "," => "July"
, "Aug" => "August", "Sept" => "Septmber", "Oct" => "October", "Nov" => "November", "Dec" => "December"
);
echo "Access array via initials AUG". $arrMonth ["Aug"]. " <br> ";
echo "############################################################<br><br><br>";
echo "Iterate through the array via foreach <br>";
echo "############################################################<br>";
foreach ($arrMonth as $key => $value) {
echo "=> key is $key, value is $value<br>";
}
echo "############################################################<br><br><br>";

/*
* Define multidimensional arrays
*/
echo "defines two-dimensional array <br>";
$arrArea =array ("East China" =>array ("Fujian", "Zhejiang"), "North China" =>array ("Beijing", "Tianjin"));
echo "East China =>". $arrArea ["East China"][0]
?>

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.