Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的代码被数组破坏了,但我无法理解_Php_Arrays - Fatal编程技术网

Php 我的代码被数组破坏了,但我无法理解

Php 我的代码被数组破坏了,但我无法理解,php,arrays,Php,Arrays,我不明白为什么$promobill($count_I)不打印任何内容。我已经为此工作了好几个小时了。有什么想法吗 $promobill是否是数组?应该是的,但我不确定它是否正确形成。此行是从原始数组生成一个随机元素数组,还是只生成一个随机元素并将其分配给变量$promobill $promo_bill = array_rand($site_promotions, $app_count); 这是我的全部代码: <?php $site_promotions = array(

我不明白为什么$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>
        ';
    }
?>

与其尝试为每道菜建立一系列促销活动,为什么不简单地为每道菜抓一次促销活动呢

foreach ($appetisers as $dish) {
    $promotion = $site_promotions[array_rand($site_promotions, 1)];
    // use $promotion
}

您似乎在计算数组开胃菜的数量,然后尝试将该数量用于站点促销,而不是dbe:

$app_count = count($site_promotions);
$promo_bill = array_rand($site_promotions, $app_count);

这是我想到的。在…看到它在行动



因为它应该是
$promo\u bill[$count\u i]
?我很确定其他一些东西都是错的,问题是我需要为每个开胃者随机选择一个促销活动。当访问者单击照片时,促销将显示在菜单翻转照片的背面。与使用
array\u rand()
时不同,这种方式可能会多次选择相同的促销。
<?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>
                    ';
                }

            ?>