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
相关文档:
asp,asp.net,php,jsp下的301转向代码
使用.htaccess文件来进行301重定向。
如果空间不支持.htaccess文件,那么我们还可以通过php/asp代码来进行301重定向。
为了将搜索引擎的记录更新到现在的域名上面,做了几个301重定向的东东,给大家分享一下.
asp 301转向代码
在 index.asp 或 default.asp 的最顶部加入以 ......
工作中用到,自己写了一个,分享给有需要的人,前面是类定义,后面2行是调用。
优点:
不需要外部图片
支持PNG透明
可自定义圆角半径
不足:
只能指定一种透明色
<?php
class RoundedCorner {
private $_r;
private $_g;
private $_b;
private $_image_path;
private $_radius;
function _ ......
openpne开源SNS
用PHP模拟126邮箱的登陆过程来收取邮件:http://www.cnblogs.com/amboyna/archive/2009/04/29/1446487.html
php调用其他系统的接口整理:http://blog.chinaunix.net/u2/84280/showart_2065156.html
问题:我是想写一个网上给手机发短信的功能 调用了一个第三方的飞信接口
飞信接口PHP版 (免费发短信) v1. ......
include实现国际化
将index.php进行翻译:
Index内容
1. Index
2. About us
我们可以将index.php设置为一个翻译模版,所有出现字符的地方,都定义为变量,如1,2部分设置为翻译的变量$menu_index, $menu_aboutus.
......
本教程采用的是xampp自带的tomcat插件来完成整合的,所以,要想完成整合,第一步不需下载xampp,及其tomcat插件~
1.打开xampp官网 点此xampp官网打开
&n ......