Home  >  Article  >  Backend Development  >  求解数组序号及所在位置解决思路

求解数组序号及所在位置解决思路

WBOY
WBOYOriginal
2016-06-13 11:55:10857browse

求解数组序号及所在位置

$arr = array (<br />  0 => <br />  array (<br />    0 => 'SU14031300617',<br />    'po_num' => 'SU14031300617',<br />  ),<br />  1 => <br />  array (<br />    0 => 'SU14031300623',<br />    'po_num' => 'SU14031300623',<br />  ),<br />  2 => <br />  array (<br />    0 => 'SU14031300626',<br />    'po_num' => 'SU14031300626',<br />  ),<br />  3 => <br />  array (<br />    0 => 'SU14031300627',<br />    'po_num' => 'SU14031300627',<br />  ),<br />  4 => <br />  array (<br />    0 => 'SU14031300616',<br />    'po_num' => 'SU14031300616',<br />  ),<br />  5 => <br />  array (<br />    0 => 'SU14031300618',<br />    'po_num' => 'SU14031300618',<br />  ),<br />  6 => <br />  array (<br />    0 => 'SU14031300622',<br />    'po_num' => 'SU14031300622',<br />  ),<br />  7 => <br />  array (<br />    0 => 'SU14031300624',<br />    'po_num' => 'SU14031300624',<br />  ),<br />  8 => <br />  array (<br />    0 => 'SU14031300625',<br />    'po_num' => 'SU14031300625',<br />  ),<br />)


假设SU14031300617这项,所在数组的位置是8项中的第1项,表示为 1/8,通过序号可求得。请问怎么求解?
------解决方案--------------------
<br />foreach($arr as $k=>$tmp) {<br />    if('SU14031300617' == $tmp[0]) {<br />        return ($k+1) . '/' . count($arr);<br />    }<br />}<br />return false;<br />

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