Home >Backend Development >PHP Tutorial > php实现最近浏览有关问题

php实现最近浏览有关问题

WBOY
WBOYOriginal
2016-06-13 13:06:40828browse

php实现最近浏览问题
function product_view($pdid)//请问这个函数里面的参数代表的是什么值
{
$limit = 8; if(is_numeric($pdid) && $pdid0)
{
if(!$_SESSION['pd_viewed'])  
{
$_SESSION['pd_viewed'] = array($pdid);
}
else  
{
if(count($_SESSION['pd_viewed'])>=$limit)
{ if(!in_array($pdid,$_SESSION['pd_viewed']))
{  
$_SESSION['pd_viewed'] = array_reverse($_SESSION['pd_viewed']);  
array_pop($_SESSION['pd_viewed']);  
$_SESSION['pd_viewed'][] = $pdid;  
$_SESSION['pd_viewed'] = array_reverse($_SESSION['pd_viewed']);  
}
}
else
{  
if(!in_array($pdid,$_SESSION['pd_viewed']))
{ $_SESSION['pd_viewed'][] = $pdid;
}
}
}

}
请帮帮我详细解释解释这个程序吧,很多的地方都看不明白呀,session里面的变量代表的是什么呀?

------解决方案--------------------
这些东西要结合整个系统来解析的,现在只能是猜

pdid应该是产品编号,至于是数据库里面的自动编号还是自定义的产品本身的编号就不清楚了

session就是把看过的编号一个个加进数组pd_viewed





最后,你好像发了不少帖子但一个都没有结,继续这样的话不会再有人回答你的问题的,不懂结贴的去社区帮助看看
------解决方案--------------------
function product_view($pdid)// $pdid 当前进入的栏目号
{
$limit = 8; // 指定最大容量
 if(is_numeric($pdid) && $pdid0) // $pdid 是数字且不为0
{
if(!$_SESSION['pd_viewed']) //如果没有从未保存过
{
$_SESSION['pd_viewed'] = array($pdid); //则保存
}
else
{ //否则插入到数组前面。 
if(count($_SESSION['pd_viewed'])>=$limit)
{ if(!in_array($pdid,$_SESSION['pd_viewed']))
{ //以下代码只需写作 array_unshift($_SESSION['pd_viewed'], $pdid);
$_SESSION['pd_viewed'] = array_reverse($_SESSION['pd_viewed']);
array_pop($_SESSION['pd_viewed']);
$_SESSION['pd_viewed'][] = $pdid;
$_SESSION['pd_viewed'] = array_reverse($_SESSION['pd_viewed']);
}
}
else
{
if(!in_array($pdid,$_SESSION['pd_viewed']))
{ $_SESSION['pd_viewed'][] = $pdid;
}
}
}
}
}

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