首页 >后端开发 >php教程 >求解数组序号及所在位置解决思路

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

WBOY
WBOY原创
2016-06-13 11:55:10893浏览

求解数组序号及所在位置

$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 />

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn