note 79176 deleted from function.array-splice by ezyang
| From: | ezyang@php.net | Date: | Wed, 14 Nov 2007 20:13:51 +0000 |
| Subject: | note 79176 deleted from function.array-splice by ezyang | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-132280@lists.php.net to get a copy of this message | ||
Note Submitter: alx at inbox dot lv
Reason: bad code
----
Enjoy in randoming a banner.
example:
<?php
$arrBanners['credit'] = array(
'i dont want to include this banner'
'i will include this banner'
);
$arrBanners['links'] = array(
'banner1'
,'banner2'
,'banner3'
);
$arrNotForTop = array(
'credit' => array(0)
);
?>
<?php
// function:
function randomBanner($arrBanners,$exclude = array()) {
$banners = array();
foreach ($arrBanners as $page => $arrBlock) {
if (array_key_exists($page,$exclude)) {
foreach ($arrBlock as $key => $banner) {
if (!array_key_exists($key,$exclude[$page])) array_push($banners,$banner);
}
continue;
}
if (!is_array($arrBlock)) {
array_push($banners,$arrBlock);
continue;
}
foreach ($arrBlock as $val) array_push($banners,$val);
}
$banners = array_unique($banners);
shuffle($banners);
return $banners[1];
}
?>
Please donate to alx@inbox.lv paypal :D