易截截图软件、单文件、免安装、纯绿色、仅160KB

PHP数组的使用和遍历

 1、数组的申请和使用:
$array=array(array(2,324,34)); 
echo   $array[0][1]; 
直接申请使用:
$student[0][0]="我";
$student[0][1]="是";
$student[1][0]="谁";
$student[1][1]="维";
 echo   $student[1][0];
2、遍历:
foreach()是一个用来遍历数组中数据的最简单有效的方法。
 
<?php
$colors = array('red','blue','green','yellow');
foreach ($colors as $color) {
echo "Do you like $color? <br />";
}
?>
 
显示结果:
Do you like red?
Do you like blue?
Do you like green?
Do you like yellow?
 
 
 
2. while()
while() 通常和 list(),each()配合使用。
#example2:
 
<?php
$colors = array('red','blue','green','yellow');

while(list($key,$val) = each($colors)) {
echo "Other list of $val.<br />";
}
?>
显示结果:
Other list of red.
Other list of blue.
Other list of green.
Other list of yellow.
 
 
 
3. for()
#example3:
 
<?php
$arr = array ("0" => "zero","1" => "one","2" => "two");

for ($i = 0;$i < count($arr); $i++) {
$str = $arr[$i];
echo "the number is $str.<br />";
}
?>
显示结果:
the number is zero.
the number is one.
the number is two.
 
 
 
========= 以下是函数介绍 ==========
key()
mixed key(array input_array)
key()函数返回input_array中位于当前指针位置的键元素。
#example4
下载: list_array04.php
 
<?php
$capitals = array("Ohio" => "Columbus","Towa" => "Des Moines","Arizona" => "Phoenix");
echo "<p>Can you name the capitals of these states?</p>";
while($key = key($capitals)) {
echo $key."<br />";
next($capitals);
//每个key()调用不会推进指针。为此要使用next()函数
}
?>
显示结果:
Can you name the capitals of these


相关文档:

Yii PHP Framework实用入门教程

说明:因为最近工作工作关系,需要开发一个在Linux下运行的Web Application,需要对现在比较流行的一些PHP框架做一个了解和评估,下面的这篇文章是笔者最近学习一个比较新的PHP Framework的一点经历和操作步骤,因为官方的手册写得比较晦涩(特别是中文的),曾经尝试遍读它那个手册再动手,读了一大半发现仍无法理解,于是 ......

Php Xml解析之DOMDocument使用方法浅解

 用到的XML文件还以“Php Xml处理之simplexml使用方法浅谈”一文中的XML为例,文件名为:me.xml。代码如下:
PHP XML处理XML代码
<?
xml

version
=
"1.0"

encoding
=
"utf-8"
?>
  
<
phplamp
>
  
    
& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号