Home  >  Article  >  Backend Development  >  尋求最快的數組求值解決方案解决办法

尋求最快的數組求值解決方案解决办法

WBOY
WBOYOriginal
2016-06-13 10:10:58749browse

尋求最快的數組求值解決方案
有一個數組,結構如下所示

$a=array(
  array('id'=>1,'text'=>'china'),
  array('id'=>10,'text'=>'usa'),
  array('id'=>6,'text'=>'uk'),
  array('id'=>9,'text'=>'canada'),


問現在我已知 一個id數為 6

我要如何操作能夠得到我所需要的值 uk

步驟越簡單越好。

------解决方案--------------------
foreach($a as $v)
if($v['id']==6) echo $v['text'];

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