Blogger Information
Blog 32
fans 0
comment 0
visits 21451
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组遍历,以及删除查看-2018年4月19日12:57:53
inhylei
Original
672 people have browsed it

数组的遍历,使用while,for,foreach 遍历数组

$pro = ['id'=>5,'status'=>'waiting','url'=>'www.url.com','name'=>'urlname', 'plan'=>'one day'];
echo '<pre>';
print_r($pro);
//foreach 打印输出数组
foreach ($pro as $key => $value) {
	echo '项目:'.$key.'&nbsp;&nbsp;详情:'.$value.'<br>';
}
// for 打印输出数组
echo '<hr>';
reset($pro);
for ($i=0; $i < count($pro); $i++) {

	echo '项目:'.key($pro). '&nbsp;&nbsp;详情:'.current($pro).'<br>';
	next($pro);
}
reset($pro);
echo '<hr>';
// while 打印输出数组
$i = 0;
while($i < count($pro)){
	echo '项目:'.key($pro). '&nbsp;&nbsp;详情:'.current($pro).'<br>';
	next($pro);
	$i++;
}

数组的增删改查

$arr1 = ['java','php','javescript','mysql','html5'];
$arr2 = array_splice($arr1,4);
$arr3 = ['python','css3','c++'];

print_r($arr2);
print_r($arr1);
$arr2 = array_splice($arr1,4,4,$arr3);
print_r($arr1);

执行结果

QQ截图20180419125921.jpg

手操代码

QQ图片20180419131353.jpg

总结,while循环,初始化变量的值,不要在最后语句添加变量的操作,不然会进入死循环;for循环语句操作记得添加指针下移next;foreach遍历数组比较简单容易掌握。

array_splice对数组的增删改查。长度为负数,则指从负数到起始点之间的元素。

Correction status:Uncorrected

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