Blogger Information
Blog 55
fans 0
comment 0
visits 50482
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP常用的键值操作和数组操作-0823
Bean_sproul
Original
850 people have browsed it

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>';
}

运行实例 »

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

 

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