Blogger Information
Blog 35
fans 2
comment 0
visits 22529
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
循环遍历--2018年4月19日
小学僧的博客
Original
569 people have browsed it

以下代码实现了for , while , foreach 对数组的循环遍历操作。

实例

<?php

$test=['t1'=>1,'t2'=>'tt','t3'=>3,'t4'=>'ts'];

for ($i=0; $i < count($test); $i++) { 
	echo '['.key($test).'=>'.current($test).']'.'<br>';
	next($test);
}
echo "<hr>";

reset($test);
$i=0;
while ($i<count($test)) {
	echo '['.key($test).'=>'.current($test).']'.'<br>';
	next($test);
	$i++;
}
echo "<hr>";

$test=['test1'=>11,'test2'=>22,'test3'=>33,'test4'=>44];

echo '<table cellspacing="0" cellpadding="5" border="1px ">';
echo '<tr align="center" bgcolor="skyblue">';
echo "<td>t1</td><td>t2</td><td>t3</td><td>t4</td>";
echo "</tr>";
echo "<tr>";

foreach ($test as $value) {
	echo "<td>".$value."</td>";
}
echo "</tr>";
echo "</table>";

echo "<hr>";
echo "移出的元素:";
print_r(array_splice($test,1,2,array('te'=>55)));
echo "<br>插入新元素后的数组:";
print_r($test);

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post