$phone = array('苹果','小米','华为','锤子','联想');
echo in_array('华为',$phone); // 1;存在返回1,不存在返回空
$computer = array(
'联想'=>'Y900P',
'神州'=>'Z8',
'苹果'=>'Sierra',
);
echo array_key_exists('联想',$computer); // 1;存在返回1,不存在返回空
$phone = array('苹果','小米','华为','锤子','联想');
echo array_search('华为',$phone); //2
$computer = array(
'联想'=>'Y900P',
'神州'=>'Z8',
'苹果'=>'Sierra',
);
echo array_search('Y900P',$computer); //联想
<?php
$computer = array(
'联想'=>'Y900P',
'神州'=>'Z8',
'苹果'=>'Sierra',
);
$keys = array_keys($computer);
var_dump($keys);
$computer = array(
'联想'=>'Y900P',
'神州'=>'Z8',
'苹果'=>'Sierra',
);
$keys = array_values($computer);
var_dump($keys);
$phone = array('苹果','小米','华为','锤子','联想','魅族');
$chunk = array_chunk($phone,3); //每3个分为一组
print_r($chunk);
$phone = array('苹果','小米','华为','锤子','联想');
$computer = array(
'联想'=>'Y900P',
'神州'=>'Z8',
'苹果'=>'Sierra',
);
$merge = array_merge($phone,$computer);
print_r($merge);
$color = array('green', 'red', 'yellow');
$fruit = array('pear', 'apple', 'banana');
$combine = array_combine($color, $fruit);
print_r($combine);
$color1 =array('a'=>'green','red','blue');
$color2 = array('b'=>'green','yellow','red');
$array = array_intersect($color1,$color2); // 索引按数组第一个;索引根据这里数组的先后顺序
print_r($array);
$color1 =array('a'=>'green','red','blue');
$color2 = array('b'=>'green','yellow','red');
$array = array_diff($color1,$color2); // 根据第一个数组来对比第二个数组没有的返回
print_r($array);
相关推荐
© 2020 asciim码
人生就是一场修行