Why call a function to add to the array? Are they coming from a datasource?
Code: Select all
$asin = array[];
array_push($asin, "B00UXTN5P0"); // GTX Titan X SC
// add more as needed
Why not just:
Code: Select all
$asin = array(
'B00UXTN5P0', // GTX Titan X SC
// add more as needed
);
I am confused how the the array above works with the function? Do you select a random item from the array and pass it to the function?
I'd rather see Presentation functions return a string that I can in turn insert into another template:
Code: Select all
function buildAISN($choice) {
$temp = '<iframe src="https://rcm-na.amazon-adsystem.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=';
$temp = $temp . $choice;
$temp = $temp . '" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>';
return $temp . "\n";
}
$str = buildAISN($aisn[array_rand($aisn)]);
Creating a class might be even cleaner (and autoloadable). Plus you could add other optional settings as needed without changing the interface to build().
Code: Select all
class Aisn
{
private $ads;
private $width = 120;
private $height = 240;
function __construct($ads)
{
$this->ads = $ads;
}
function setSize($width, $height)
{
$this->width = $width;
$this->height = $height;
}
function build()
{
$temp = '<iframe src="https://rcm-na.amazon-adsystem.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=cpa07-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=';
$temp .= $this->ads[array_rand($$this->ads)]);
$temp .= $temp . '" style="width:' . $this->width . 'px;height:' . $this->height . 'px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>';
return $temp . "\n";
)
}
$ad = new Aisn($aisnStandard);
$str = $ad->build();
$ad = new Aisn($aisnLarge);
$ad->setSize(160, 600);
$str = $ad->build();