【php5.5新数组函数array_column使用】教程文章相关的互联网学习教程文章

php数组函数in_array()查找数组值是否存在

在php编程中,in_array() 函数在数组中搜索给定的值。 in_array() 定义和用法 in_array() 函数在数组中搜索给定的值。 语法 in_array(value,array,type) 参数 描述 value 必需。规定要在数组搜索的值。 array 必需。规定要搜索的数组。 type 可选。如果设置该参数为 true,则检查搜索的数据与数组的值的类型是否相同。 说明 如果给定的值 value 存在于数组 array 中则返回 true。如果第三个参数设置为 true,函数只有在元素...

php返回数组中指定的一列(php5.5.0默认函数array_column()在php<5.5.0的应用)

array_column() 返回数组中指定键名的列(PHP 5 >= 5.5.0)array_column — 返回数组中指定的一列php参考手册:http://www.php.com/manual/zh/function.array-column.php如果php版本小于5.5.0怎么办呢?我们自定义一个以下代码摘自onethink /** * 返回数组中指定的一列 * http://www.onethink.cn * /Application/Common/Common/function.php * * array_column — PHP 5 >= 5.5.0 默认函数 * PHP 5 < 5.5.0 则使用自定义函数 * * @...

改进array_unique($array)函数

改进后不用再按处理前的数组的长度遍历,直接按处理后的数组长度遍历即可 function unique($array) { sort($array); $arraylength=count($array); $endarray=array(); for ($i=0;$i<$arraylength;$i++) { if ($i!="0") { $nextvalue=$array[$i-1]; }else{ $nextvalue=""; } if ($i!=$arraylength) { $prevalue=$array[$i+1]; }else{ $prevalue=""; } $currentvalue=$array[$i]; if($currentvalue==$nextvalue||$currentvalue=...

php函数array_merge()用法一例(合并同类数组)

$arr1 = $dblink->mem_fetch_array ( "SELECT t_pid,imgname,invented,score FROM `t_sum_giftimg` where t_pid=3 or t_pid=6", 0 ); $arr2 = $dblink->mem_fetch_array ( "SELECT t_pid,imgname,invented,score FROM `t_sum_giftimg` where t_pid=10 or t_pid=12", 0 ); $imgInfo = array_merge ( $arr1, $arr2 ); if ($imgInfo) { foreach ( $imgInfo as $imgInfo ) { $imgs [] = $imgInfo; } }您可能感兴趣...

php的mssql_fetch_row、mssql_fetch_array、mssql_fetch_assoc及mssql_fetch_objcect读取数据的

require 'dbconn.php';$sql = 'select * from _Test';$query = mssql_query($sql);while($row=mssql_fetch_row($query)){echo $row['UserId'].'::'.$row[1].'';}返回: Notice: Undefined index: UserId in D:/_PHP_Test/Test2/test_connLocalDB.php on line 32 ::王小一 Notice: Undefined index: UserId in D:/_PHP_Test/Test2/test_connLocalDB.php on line 32 ::王小二 Notice: Undefined index: UserId in D:/_PHP_Test/Test2...

php使用array_unique判断数组中是否存在相同的值

<?php $input = array("a" => "green", "red", "b" => "green", "blue", "red"); $result = array_unique($input); print_r($result); ?>输出结果: Array ( [a] => green [0] => red [1] => blue ) 例2. array_unique() 和类型 <?php $input = array(4, "4", "3", 4, 3, "3"); $result = array_unique($input); var_dump($result); ?>输出结果: array(2) { [0] => int(4) [2] => string(1) "3" }

php数组函数array_key_exists()查找数组键名是否存在

$a=array("a"=>"Dog","b"=>"Cat");if (array_key_exists("a",$a)){echo "Key exists!";}else{echo "Key does not exist!";}?>输出: Key exists! 例2:$a=array("a"=>"Dog","b"=>"Cat");if (array_key_exists("c",$a)){echo "Key exists!";}else{echo "Key does not exist!";}?>输出: Key does not exist! 例3:$a=array("Dog",Cat");if (array_key_exists(0,$a)){echo "Key exists!";}else{echo "Key does not exist!";}?>输出:...

php数组函数in_array()查找数组中是否存在指定值

$people = array("Peter", "Joe", "Glenn", "Cleveland");if (in_array("Glenn",$people)){echo "Match found";}else{echo "Match not found";}?>输出: Match found 例2:$people = array("Peter", "Joe", "Glenn", "Cleveland", 23);if (in_array("23",$people, TRUE)){echo "Match found";}else{echo "Match not found";}if (in_array("Glenn",$people, TRUE)){echo "Match found";}else{echo "Match not found";}if (in_array(...

php拆分数组的二个函数(array_slice()、array_splice())

$input = array("a", "b", "c", "d", "e");$output = array_slice($input, 2); // returns "c", "d", and "e"$output = array_slice($input, -2, 1); // returns "d"$output = array_slice($input, 0, 3); // returns "a", "b", and "c"// note the differences in the array keysprint_r(array_slice($input, 2, -1));print_r(array_slice($input, 2, -1, true));?>上例将输出: Array ( [0] => c [1] => d ) Array ( [2] => c [3...

php数组函数array_map、array_multisort多维数组排序实例

<?phparray_sort($arrFile, 1, 1);//根据name字段排序 array_sort($arrFile, 3, 1);//根据size字段排序 /* @records 要排序的数组 @field要排序的字段,注意是数字 @reverse正序还是反序 */ function _array_sort($records, $field, $reverse, $defaultSortField = 0) { $uniqueSortId = 0; $hash = array(); $sortedRecords = array(); $tempArr = array(); $indexedArray = array(); $recordArray = array();foreach($records as ...

php数组函数array_multisort()用法

$arr1 = array('10', 11, 100, 100, 'a'); $arr2 = array(1, 2, 3, '2', 5); array_multisort($arr1, $arr2); ?>结果为: $arr1 Array ( [0] => 10 [1] => a [2] => 11 [3] => 100 [4] => 100 ) # 10在与11, 100, 100比较时转换为整数10,小于其他三个数 # 10在于a比较时作为字符串,其第一个字符1ascii码值为49小于‘a(ascii值为97),所以‘10为最小元素 # a在于其他三个数字比较时,转换为整数0,小于其他三个数 $arr2 ...

php数组排序函数array_multisort与uasort的区别

function my_sort($a, $b) { if ($a == $b) return 0; return ($a > $b) ? -1 : 1; } $people = array("Swanson" => "Joe", "Griffin" => "Peter", "Quagmire" => "Glenn", "swanson" => "joe", "griffin" => "peter", "quagmire" => "glenn"); uasort($people, "my_sort"); print_r ($people); ?>输出结果: Array ( [griffin] => peter [swanson] => joe [quagmire] => glenn [Griffin] => Peter [Swanson] => Joe [Quag...

加强版的array_unique函数(支持二维数组)

//二维数组去掉重复值function array_unique_fb($array2D){ foreach ($array2D as $v){ $v = join(“,”,$v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串 $temp[] = $v; } $temp = array_unique($temp); //去掉重复的字符串,也就是重复的一维数组 foreach ($temp as $k => $v){ $temp[$k] = explode(“,”,$v); //再将拆开的数组重新组装 } return $temp;...

phpin_array用法一例

php in_array用法一例,供大家学习参考。示例代码:Output: Its Here.

php中array_key_exists与isset的区别

本文介绍下,php语言中的array_key_exists与isset的区别,有需要的朋友参考下吧。php中array_key_exists与isset有哪些区别呢? 1,对于数组值的判断不同,对于值为null或或false,isset返回false,array_key_exists返回true; 2,执行效率不同,isset是内建运算符,array_key_exists是php内置函数,isset要快一些。 3,当用isset访问一个不存在索引数组值时,不会引起一个E_NOTICE的php错误消息; 4,array_key_exists 会调用get_de...

PHP5 - 相关标签