Home  >  Article  >  Backend Development  >  PHP代码ip2long 循环有关问题

PHP代码ip2long 循环有关问题

WBOY
WBOYOriginal
2016-06-13 12:15:481095browse

PHP代码ip2long 循环问题

print_r($dataIp);<br />            foreach ($dataIp as $key=>$value) {<br />                $data['ip']     =   $value;<br />                $data['iplong']     =   bindec(decbin(ip2long($value)));                            <br />                print_r($data);             <br />            }


打印出来的结果为:

引用
Array
(
[0] => 208.104.70.215
[1] => 74.101.176.171
[2] => 73.17.35.30
[3] => 70.198.197.3
[4] => 46.44.179.76
)
====
Array
(
[ip] => 208.104.70.215
[iplong] => 0
)
Array
(
[ip] => 74.101.176.171
[iplong] => 0
)
Array
(
[ip] => 73.17.35.30
[iplong] => 0
)
Array
(
[ip] => 70.198.197.3
[iplong] => 0
)
Array
(
[ip] => 46.44.179.76
[iplong] => 774681420
)

只有最后一个转换成功了,其他的都失败了,这是什么原因?
------解决思路----------------------
没有问题
Array<br />(<br />    [ip] => 208.104.70.215<br />    [iplong] => 3496494807<br />)<br />Array<br />(<br />    [ip] => 74.101.176.171<br />    [iplong] => 1248178347<br />)<br />Array<br />(<br />    [ip] => 73.17.35.30<br />    [iplong] => 1225859870<br />)<br />Array<br />(<br />    [ip] => 70.198.197.3<br />    [iplong] => 1187431683<br />)<br />Array<br />(<br />    [ip] => 46.44.179.76<br />    [iplong] => 774681420<br />)<br /><br />

但不知你想干什么
------解决思路----------------------
<br /><?php<br />$dataIp = array('208.104.70.215', '74.101.176.171', '73.17.35.30', '70.198.197.3', '46.44.179.76');<br /><br />foreach ($dataIp as $key=>$value) {<br />		$data['ip']     =   $value;<br />		$data['iplong']     =   bindec(decbin(ip2long($value)));                            <br />		print_r($data);             <br />}<br />

输出
<br />Array<br />(<br />    [ip] => 208.104.70.215<br />    [iplong] => 3496494807<br />)<br />Array<br />(<br />    [ip] => 74.101.176.171<br />    [iplong] => 1248178347<br />)<br />Array<br />(<br />    [ip] => 73.17.35.30<br />    [iplong] => 1225859870<br />)<br />Array<br />(<br />    [ip] => 70.198.197.3<br />    [iplong] => 1187431683<br />)<br />Array<br />(<br />    [ip] => 46.44.179.76<br />    [iplong] => 774681420<br />)<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