我无法弄清楚为什么$ promobill($ count_i)不会打印任何内容。我已经和他一起工作了好几个小时,把头靠在墙上。有什么想法吗?
$ promobill是不是一个数组?它应该是,但我不确定它是否正确形成。这行是否会从原始数组中产生一个随机元素数组,或者只产生一个随机元素并将其赋值给变量$ promobill?
$promo_bill = array_rand($site_promotions, $app_count);
这是我的完整代码:
<?php
$site_promotions = array(
'Free appetiser - orders over $3,000',
'$100 off first time orders!',
'testing...'
);
$appetisers = array(
array('Pomegranate Shrimp','Jumbo shrimp sauteed with shitake mushrooms, herbs and pomegranate molasses.','#'),
array('Hummus','Chick peas blended with tahini, garlic and lemon juice; topped with olive oil.','#'),
array('Baba Ghannouj','Roasted eggplant blended with tahini, fresh garlic, parsley and lemon juice; topped with olive oil.','#'),
array('Persian SaladPersian Salad','Freshly diced cucumbers, tomatoes and red onions tossed with lemon juice and a pinch of mint.','#'),
array('Kash-Ke-Bademjan','Roasted eggplant purees with onion, garlic, mint and Kashk (aged, dried yogurt); topped with caramelized onions and kask.','#'),
array('Must O Khiar','Homemade yogurt, freshly diced cucumbers and mint. Smooth and refreshing!','#'),
array('Moosir','Persian Shallot finely sliced mixed with thich homemade yogurt. Try it, you\'ll like it.','#'),
array('Olovieh','Persian potato salad with chopped chicken breast, pickles, peas, shredded carrots & mayonnaise.','#'),
array('Caspian Eggplant','Mix of sweet charbroiled eggplant, tomato, onion & garlic topped with moosir.','#'),
array('Pomegranate Mushrooms','Your choice of mushrooms flavored with exotic herbs, garlic, olive oil & pomegranate molasses.','#'),
array('Dolmeh Felfel','Two bell peppers stuffed with basmati rice, cracked wheat, herbs & vegtables, baked in tomato saffron sauce.','#'),
array('Dolmeh','Grape leaves stuffed with rice, tomato, onion, herbs & spices in tomato saffron sauce.','#'),
array('Borani','Fresh spinach sautéed with onions and garlic in extra virgin olive oil and mixed with homemade yogurt.','#'),
array('Spicy Pomegranate Wings','Charbroiled chicken wings with pomegranate glaze (7). Yummy, yummy, yummy!','#'),
array('Falafel','Chickpeas seasoned and lightly fried served with tahini sauce.','#'),
array('Persian Garden Salad','Crispy romaine, spring mix, red onions, cucumbers, cherry tomato, olives & Bulgarian cheese.','#')
);
$app_count = count($appetisers);
$promo_bill = array_rand($site_promotions, $app_count);
foreach($appetisers as $dish)
{
$count_i=key($dish);
echo'
<div class="sponsor" title="Click to flip">
<div class="sponsorFlip">
<a class="group1" href="img/appetisers.jpg" title="'.$dish[0].'">
<img class="sponsorIMG" src="img/appetisers_t.jpg" alt="Donya Catering menu" />
</a>
<div class="dish_name">'.$dish[0].'</div>
</div>
<div class="sponsorData">
<div class="sponsorDescription">'.$dish[1].'</div>
<div class="sponsorURL">
<a class="sponsorLINK" href="promos/.'$promobill($count_i)'.">'.$promo_bill($count_i).'</a>
</div>
</div>
</div>
';
}
?>
答案 0 :(得分:1)
这是我想出的。请参阅JSFiddle ...
中的实际操作<?php
$promotions = array();
$promos = array();
$promotions1 = array();
foreach (explode("\n", file_get_contents('http://donyacatering.com/st/wp-content/themes/DonyaCatering/data/promotions.txt')) as $promotions1) {
$promotions[] = explode(",", $promotions1);
}
$appetisers = array(
array('Pomegranate Shrimp','Jumbo shrimp sauteed with shitake mushrooms, herbs and pomegranate molasses.','http://donyacatering.com/'),
array('Hummus','Chick peas blended with tahini, garlic and lemon juice; topped with olive oil.','http://donyacatering.com/'),
array('Baba Ghannouj','Roasted eggplant blended with tahini, fresh garlic, parsley and lemon juice; topped with olive oil.','http://donyacatering.com/'),
array('Persian SaladPersian Salad','Freshly diced cucumbers, tomatoes and red onions tossed with lemon juice and a pinch of mint.','http://donyacatering.com/')
);
foreach($appetisers as $id=>$dish)
{
$r=rand(0, count($promotions) - 1);
$promos[$id][0] = $promotions[$r][0];
$promos[$id][1] = $promotions[$r][1];
echo'
<div class="sponsor" title="Click to flip">
<div class="sponsorFlip">
<a class="group1" href="http://donyacatering.com/st/wp-content/themes/DonyaCatering/img/appetisers.jpg" title="'.$dish[0].'<br>'.$dish[1].'">
<img class="sponsorIMG" src="http://donyacatering.com/st/wp-content/themes/DonyaCatering/img/appetisers_t.jpg" alt="Donya Catering menu" />
</a>
<div class="dish_name">'.$dish[0].'</div>
</div>
<div class="sponsorData">
<div class="sponsorURL">
<a class="sponsorLINK" href="http://donyacatering.com/st/wp-content/themes/DonyaCatering/promos/'.$promos[$id][1].'" title="'.$promos[$id][1].'">'.$promos[$id][0].'</a>
</div>
</div>
</div>
';
}
?>
答案 1 :(得分:0)
不是试图为每道菜建立一系列促销活动,为什么不简单地为每个项目获得一个促销活动?
foreach ($appetisers as $dish) {
$promotion = $site_promotions[array_rand($site_promotions, 1)];
// use $promotion
}
答案 2 :(得分:0)
你似乎在计算数组开胃菜,然后尝试将这个计数用于site_promotions,而不是它应该是dbe:
$app_count = count($site_promotions);
$promo_bill = array_rand($site_promotions, $app_count);