我有一个视图论坛帖子脚本
if(isset($replys)){
foreach ($replys as $reply) {
echo $reply['name'].' | '.$reply['date'];
}
}
输出如:
abc | 2013-1-1
123 | 2013-1-2
456 | 2013-1-3
然后我想随机展示广告 例如:
abc | 2013-1-1
Google Ads | testing
123 | 2013-1-2
456 | 2013-1-3
使用if语句:
if( is_string(substr(sha1(uniqid()),-1)) ){
// show ads
}
我该怎么做?
答案 0 :(得分:1)
找一个随机点来插入广告:
if (is_string(substr(sha1(uniqid()),-1))) {
// show ads
$offset = mt_rand(0, count($replys) - 1);
$ad = array('name' => 'Google Ads', 'date' => 'testing');
$replys = array_splice($replys, $offset, 0, $ad);
}