- is_number 检查变量是否为数字或是数字字符串
说明: is_number(mixed var):bool
//说明:array_column(array $input ,mixed $column_key [,mixed $index_key=null]):array
$records = array(
array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
),
array(
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
),
array(
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
)
);
$first_names =array_colum($records,'first_name');
print_r($first_names);
// 输出:
Array
(
[0] => John
[1] => Sally
[2] => Jane
[3] => Peter
)
$list_names=array_column($records,'list_name','id');
print_r($list_names);
// 输出:
Array
(
[2135] => Doe
[3245] => Smith
[5342] => Jones
[5623] => Doe
)
- array_search 在数组中搜索给定的值,如果成功返回首个相应的键名
//说明 :array_search(mixed $needle,array $haystack [,bool $strict=false]);mixed;
//如果可选的第三个参数 strict 为true ,则 array_search()将在haystack 中检查却完全相同的元素.需要比较$needle 的类型.并且对象需要时同一个实例.
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key=array_search('green',$array);//key=2;
$key=array_search('red',$array);//key=3;
$key=array_search('white',$array);//key=false;
// 说明 in_array(mixed $neeld,array $haystack [,bool $string=FALSE]):bool
//区分大小写
$os = array("Mac", "NT", "Irix", "Linux");
if(in_array('Irix',$os)){
echo "got Irix";
}
if(in_array('max',$os)){
echo "got max";
}
// 输出: Got Irix (in_array 区分大小写)
//说明 : array_unique(array $array[,int $sort_flags = SORT_STRING]):array
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
// 输出:
Array
(
[a] => green
[0] => red
[1] => blue
)
image.png
网友评论