Correction status:qualified
Teacher's comments:
in_array()判断数组中是否存在某个值
<?php $user =['id'=>5, 'name'=>'xiaoyang','gender'=>'man','age'=>16]; echo in_array('peter',$user) ? '存在<br>' : '不存在<br>';
点击 "运行实例" 按钮查看在线实例
array_key_exists():判断某个键名是否存在于数组中?
<?php $user =['id'=>5, 'name'=>'xiaoyang','gender'=>'man','age'=>16]; echo array_key_exists('salary',$user) ? '存在<br>' : '不存在<br>';
点击 "运行实例" 按钮查看在线实例
array_values():以索引方式返回数组的值 组成的数组
<?php $user =['id'=>5, 'name'=>'xiaoyang','gender'=>'man','age'=>16]; print_r(array_values($user));
点击 "运行实例" 按钮查看在线实例
array_keys()以索引方式返回数组的健 组成的数组
<?php $user =['id'=>5, 'name'=>'xiaoyang','gender'=>'man','age'=>16]; print_r(array_keys($user));
点击 "运行实例" 按钮查看在线实例
array_search():以字符串的方式返回指定值的键
$user =['id'=>5, 'name'=>'xiaoyang','gender'=>'man','age'=>16]; echo $user[array_search('peter',$user)];
点击 "运行实例" 按钮查看在线实例
array_flip()键值对调
<?php $user =['id'=>5, 'name'=>'xiaoyang','gender'=>'man','age'=>16]; print_r(array_flip($user));
点击 "运行实例" 按钮查看在线实例
//count(数组变量)计算出数组中有多少条数据
//key()返回当前元素的键
//current()返回当前元素的值
//next()指针下移
//reset()复位
//end()尾部
//each()返回当前元素的键值的索引与关联的描述,并自动下移
// while,list(),each() 遍历数组
<?php $user =['id'=>5, 'name'=>'xiaoyang','gender'=>'man','age'=>16]; echo count($user),'<br>'; //key()返回当前元素的键 echo key($user),'<br>'; //current()返回当前元素的值 echo current($user),'<hr>'; //next()指针下移 next($user); echo key($user),'<br>'; echo current($user),'<hr>'; next($user); echo key($user),'<br>'; echo current($user),'<hr>'; //reset()复位 reset($user); echo key($user),'<br>'; echo current($user),'<hr>'; //end()尾部 end($user); echo key($user),'<br>'; echo current($user),'<br>'; reset($user); //each()返回当前元素的键值的索引与关联的描述,并自动下移 print_r(each($user)); //print_r(each($user)); //list() //将索引数组中的值,赋值给一组变量 list($key, $value) = each($user); echo $key, '******', $value,'<hr>'; // while,list(),each() 遍历数组 reset($user); while (list($key, $value) = each($user)) { echo $key , ' => ', $value, '<br>'; }
点击 "运行实例" 按钮查看在线实例