【发布时间】:2012-01-11 02:26:51
【问题描述】:
几分钟后,我意识到我遇到的错误:神奇的2147483647 数字,即 PHP/32 上integer 类型的上限。我需要在我的函数中管理更大的数字:
public function albumExists($name) // e.g. 104112826372452
{
$albums = $this->getAlbums();
// If $name is int, search the key in $albums
if(is_int($name) && ($found = array_key_exists($id = intval($name), $albums)))
return ($found ? $id : false);
// Start looking for $name as string
foreach($album as $id => $a) if ($a->name == $name) return intval($id);
return false; // Found nothing
}
为了能够同时通过id 和name 进行搜索。但是intval() 总是会返回上限。如何处理相当大的数字,比如104112826372452?想法?
编辑:用法示例:
$album = $fb->createAlbum('Test Album'); // Will return album id
// The use albumExists to check if id exists
$photo1 = $fb->uploadPhoto('mypic1.png', null, $album);
$photo2 = $fb->uploadPhoto('mypic2.png', null, 'Test Album'); // find or create
【问题讨论】: