Home php教程 php手册 php入门学习知识点五 关于php数组的几个基本操作_php入门_脚本之

php入门学习知识点五 关于php数组的几个基本操作_php入门_脚本之

Jun 06, 2016 pm 08:37 PM
php array

php入门学习知识点五 关于php数组的几个基本操作,数组是php中最常用的,所以大家一定要熟练的掌握。

代码如下:
/*
* 简单的数组定义与访问
*/
echo "简单的数组定义与访问
";
echo "############################################################
";
$address=array(5);
$address[0]="福州";
$address[1]="厦门";
$address[2]="漳州";
$address[3]="泉州";
$address[4]="宁德";
$address[5]="南平";
$address[6]="龙岩";
echo "我现在住在$address[1]
";
echo "############################################################


";
/*
* 数组遍历
*/
echo "通过for循环进行数组遍历
";
echo "############################################################
";
for($index=0;$indexprint("数组中第".$index."个的地区$address[$index]为
");
}
echo "############################################################


";
/*
* 数组初始化
*/
echo "数组初始化,并通过日期函数得到当前月份的数字,输出相关数组下标的内容
";
echo "############################################################
";
$arrMonth=array("January","February","March","April","May","June","July","August","September","October","November","December");
date_default_timezone_set("utc"); //设置默认时区
$month=date("m");
echo "数组结构为";
print_r($arrMonth);
echo "当前是第".$month."月,他的英文是".$arrMonth[$month-1]."
";
echo "############################################################


";
/*
*数组初始化,并定义键,然后通过键值访问数组
*/
echo "数组初始化,并定义键,然后通过键访问数组
";
echo "############################################################
";
$arrMonth=array("Jan"=>"January","Feb"=>"February","Mar"=>"March","Apr"=>"April","May"=>"May","Jun"=>"June","Jul"=>"July"
,"Aug"=>"August","Sept"=>"Septmber","Oct"=>"October","Nov"=>"November","Dec"=>"December"
);
echo "通过英文缩写Aug 访问数组".$arrMonth["Aug"]."
";
echo "############################################################


";
echo "下面通过Foreach遍历数组
";
echo "############################################################
";
foreach ($arrMonth as $key=>$value){
echo " =>键是$key,值是$value
";
}
echo "############################################################


";

/*
* 定义多维数组
*/
echo "定义二维数组
";
$arrArea=array("华东地区"=>array("福建","浙江"),"华北地区"=>array("北京","天津"));
echo "华东地区=>".$arrArea["华东地区"][0]
?>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use PHP arrays to generate and display charts and statistical graphs How to use PHP arrays to generate and display charts and statistical graphs Jul 15, 2023 pm 12:24 PM

How to use PHP arrays to generate and display charts and statistical graphs

How to use PHP arrays to generate dynamic slideshows and image displays How to use PHP arrays to generate dynamic slideshows and image displays Jul 15, 2023 pm 01:17 PM

How to use PHP arrays to generate dynamic slideshows and image displays

How to use PHP arrays to implement user login and permission management functions How to use PHP arrays to implement user login and permission management functions Jul 15, 2023 pm 08:55 PM

How to use PHP arrays to implement user login and permission management functions

What are php array key-value pairs? What are php array key-value pairs? Aug 03, 2023 pm 02:20 PM

What are php array key-value pairs?

How to determine how many arrays there are in php How to determine how many arrays there are in php Aug 04, 2023 pm 05:40 PM

How to determine how many arrays there are in php

Effective implementation of array union in PHP Effective implementation of array union in PHP Apr 30, 2024 pm 01:03 PM

Effective implementation of array union in PHP

An exploration of performance optimization techniques for PHP arrays An exploration of performance optimization techniques for PHP arrays Mar 13, 2024 pm 03:03 PM

An exploration of performance optimization techniques for PHP arrays

What is the function in PHP to determine if an array is empty? What is the function in PHP to determine if an array is empty? Aug 03, 2023 pm 05:15 PM

What is the function in PHP to determine if an array is empty?

See all articles