Home  >  Article  >  Backend Development  >  php怎么获取二维数组指定的某个字段的值?

php怎么获取二维数组指定的某个字段的值?

WBOY
WBOYOriginal
2016-06-23 13:41:521887browse

需求:有如下数组$arr,数组中有两个模块一个net 一个login,我怎么根据net模块获取最后一个marks,
其中net模块和login模块的数据还是一条一条正往$arr里插,net模块亦可能是 find add up  del  chark 或者更多字段,
就是不管他插多少,我上来一下能找到最后一个marks,如现在你找到del 下的最后一个marks ,前提是我不知道del是组后一个,我要是知道的话,我搞个索引就好了,还有个foreach ,不要遍历,遍历速度不快,谁能给个速度快点?

$arr = array("net" => array(                                       "find" => array("marks"=>"1234","name"=>"lisi"),                                       "add" => array("marks"=>"12","name"=>"lisi2"),                                       "up" => array("marks"=>"15","name"=>"lisi3"),                                       "del" => array("marks"=>"9","name"=>"lisi4")                               ),                           "login" => array(                                      "find" => array("marks"=>"16661","name"=>"lisi5"),                                      "add" => array("marks"=>"18881","name"=>"lisi6")                               )                          );


回复讨论(解决方案)

$v = end($arr['net']);$k = key($arr['net']);echo $k;print_r($v);

楼上真棒  呵呵

 学习了


真给力,学习了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn