我想从以这种格式保存的单个记录中获取IP:
a:10:{i:0;a:6: {s:2:"ip";s:12:"92.74.183.58";s:7:"country";N;s:7:"browser";s:0:"";s:2:"os";s:0: "";s:8:"referrer";s:16:"www.mysite.com";s:4:"time";i:1384112675;}i:1;a:6: {s:2:"ip";s:14:"94.218.210.161";s:7:"country";N;s:7:"browser";s:0:"";s:2:"os";s: 0:"";s:8:"referrer";s:12:"mysite.com";s:4:"time";i:1381001719;}i:2;a:6: {s:2:"ip";s:14:"109.193.141.97";s:7:"country";N;s:7:"browser";s:0:"";s:2:"os";s: 0:"";s:8:"referrer";s:16:"www.mysite.com";s:4:"time";i:1373617006;}i:3;a:6:{s:2:"ip";s:13:"77.29.163.221";s:7:"country";N;s:7:"browser";s:0:"";s:2:"os";s:0:"";s:8:"referrer";s:16:"www.mysite.com";s:4:"time";i:1372942359;}i:4;a:6:{s:2:"ip";s:13:"77.29.163.221";s:7:"country";N;s:7:"browser";s:0:"";s:2:"os";s:0:"";s:8:"referrer";s:16:"www.mysite.com";s:4:"time";i:1372942159;}i:5;a:6:{s:2:"ip";s:12:"77.29.163.83";s:7:"country";N;s:7:"browser";s:0:"";s:2:"os";s:0:"";s:8:"referrer";s:16:"www.gigaodds.com";s:4:"time";i:1372889274;}i:6;a:6:{s:2:"ip";s:14:"46.217.104.220";s:7:"country";N;s:7:"browser";s:0:"";s:2:"os";s:0:"";s:8:"referrer";s:12:"mysite.com";s:4:"time";i:1372438492;}i:7;a:6:{s:2:"ip";s:14:"46.217.104.220";s:7:"country";N;s:7:"browser";s:0:"";s:2:"os";s:0:"";s:8:"referrer";s:16:"www.mysite.com";s:4:"time";i:1372438135;}i:8;a:6:{s:2:"ip";s:14:"46.217.207.213";s:7:"country";N;s:7:"browser";s:0:"";s:2:"os";s:0:"";s:8:"referrer";s:16:"www.mysite.com";s:4:"time";i:1372368077;}i:9;a:6:{s:2:"ip";s:14:"109.192.181.68";s:7:"country";N;s:7:"browser";s:0:"";s:2:"os";s:0:"";s:8:"referrer";s:16:"www.mysite.com";s:4:"time";i:1370461381;}}
我正在尝试仅获取最后一个IP,而不是获取此记录中保存的所有IP。
$user_login_info = unserialize($user_info['u_login_info']);
foreach ($user_login_info as $info) {
$ip = $info['ip'];
echo $ip;
echo "<br />";
}
最佳答案
$user_login_info = unserialize($user_info['u_login_info']);
$lastIp = end($user_login_info);
关于php - Foreach循环使用php获取记录中数组的最后一项?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28320511/