博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP 多维数组 Key Value的使用
阅读量:6203 次
发布时间:2019-06-21

本文共 1649 字,大约阅读时间需要 5 分钟。

"60", "num" => "56", "count" => "31");$user["61"] = array("id" => "61", "num" => "22", "count" => "34");$user["59"] = array("id" => "59", "num" => "32", "count" => "43");$user["56"] = array("id" => "56", "num" => "41", "count" => "38");$user["57"] = array("id" => "57", "num" => "39", "count" => "65");$values = array_values($user);//返回数组的所有值(非键名)$keys = array_keys($user);//返回包含数组中所有键名的一个新数组$iskey=array_key_exists("57",$user);//检查某个数组中是否存在指定的键名,如果键名存在则返回 true,如果键名不存在则返回 false。$iskey=array_key_exists(57,$user); //结果同上,不依赖类型,数字 57 与字符串 "57" 是相同的。$key =array_keys($keys,57) ;// 函数返回包含数组中所有键名的一个新数组。如果提供了第二个参数,则只返回键值为该值的键名。$result['status'] = 0;$result['res']=count($key);//$result['res'] = $user;//-----------返回值是对象://-----------{"status":0,"res":{"60":{"id":"60","num":"56","count":"31"},"61":{"id":"61","num":"22","count":"34"},"59":{"id":"59","num":"32","count":"43"},"56":{"id":"56","num":"41","count":"38"},"57":{"id":"57","num":"39","count":"65"}}}//$result['res'] = $values;//-----------返回值是数组://-----------{"status":0,"res":[{"id":"60","num":"56","count":"31"},{"id":"61","num":"22","count":"34"},{"id":"59","num":"32","count":"43"},{"id":"56","num":"41","count":"38"},{"id":"57","num":"39","count":"65"}]}//$result['res'] = $keys;//-----------返回值是key的一维数组://-----------{"status":0,"res":[60,61,59,56,57]}//sort($user);//按key排序之后,key被过滤掉//$result['res'] = $user;//-----------返回值是按key排序(不包括key)的多维数组://-----------{"status":0,"res":[{"id":"56","num":"41","count":"38"},{"id":"57","num":"39","count":"65"},{"id":"59","num":"32","count":"43"},{"id":"60","num":"56","count":"31"},{"id":"61","num":"22","count":"34"}]}echo json_encode($result);?>

 

转载地址:http://qxhca.baihongyu.com/

你可能感兴趣的文章
mysql cluster 7.1搭建
查看>>
Configuring Aggregated Ethernet Interfaces
查看>>
我的友情链接
查看>>
电脑公司 Ghost XP SP3 国庆特别版 v2011.10
查看>>
Linux系统软件包的管理 3月30日课程
查看>>
指针3
查看>>
我的友情链接
查看>>
C/C++面试题(一)
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
Asp.net页面和Html页面之间的关系
查看>>
设置开机自启动服务
查看>>
VNX NETAPP NAS 备份恢复
查看>>
c/c++编译器的安装
查看>>
NFS共享存储服务部署
查看>>
solidity开发以太坊代币智能合约
查看>>
接口测试
查看>>
深入理解Linux守护进程
查看>>
windows服务器下的ftp server搭建
查看>>
如何在C#中使用Win32和其他库之三
查看>>