Blogger Information
Blog 20
fans 0
comment 0
visits 14871
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组常用的指针操作 2018.8.23
李逍遥
Original
680 people have browsed it

实例

<?php
header('content-type:text/html;charset=utf-8');
$userName = ['name'=>'李逍遥','sex'=>'man','age'=>'23'];
echo '<pre>',print_r($userName,true);
//数组的内部指针操作
echo count($userName),'<br>';//计算数组当前有多少元素

//key() 返回当前元素的键
echo key($userName),'<br>';
//current() 返回当前元素的值
echo current($userName),'<hr>';

//next() 指针下移
next($userName);
echo key($userName),'<br>';
echo current($userName),'<br>';

next($userName); //再次下移
echo key($userName),'<br>';
echo current($userName),'<hr>';

//reset() 复位 指针复位
reset($userName);
echo key($userName),'<br>';
echo current($userName),'<hr>';

//end() 尾部 移动到尾部
end($userName);
echo key($userName),'<br>';
echo current($userName),'<br>';
reset($userName);

//each() 返回当前元素键值的索引 及 关联的描述,并自动下移 每执行一次就下移一次
print_r(each($userName));
print_r(each($userName));  //第二次下移 执行一次下移一次

//list() 将索引数组中的值,赋值给一组变量
list($key,$value) = each($userName);  // 第三次下移 each() 执行一次下移一次
echo $key,$value;

?>

运行实例 »

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


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