PHP:开关盒未按预期提供图像

PHP:开关盒未按预期提供图像,php,image,function,switch-statement,var,Php,Image,Function,Switch Statement,Var,我是新手 问题:我预计两(2)个图像将出现在h1中,这是由switch case交付(并随机)的。一个是以标准方式交付的,并且会出现,但另一个是通过var$widget01交付的,不会出现 现在,我知道该函数在我进行测试时工作(h1中的第一个映像由函数ok交付),但是当我尝试使用$widget01 var交付它时,什么也没有发生 我试图弄清楚如何使用我的配置将内容传递到一个页面,而不是另一个页面。为了做到这一点,我需要让开关用例将它们传递到我的测试页面(然后我可以在该条上将var设置为null

我是新手

问题:我预计两(2)个图像将出现在h1中,这是由switch case交付(并随机)的。一个是以标准方式交付的,并且会出现,但另一个是通过var$widget01交付的,不会出现

现在,我知道该函数在我进行测试时工作(h1中的第一个映像由函数ok交付),但是当我尝试使用$widget01 var交付它时,什么也没有发生

我试图弄清楚如何使用我的配置将内容传递到一个页面,而不是另一个页面。为了做到这一点,我需要让开关用例将它们传递到我的测试页面(然后我可以在该条上将var设置为null以不传递它)。我很擅长如何不交付,但我无法让它交付,因此图像将如希望的那样出现

代码如下

我的'config.php'中的代码: //config.php

   include 'credentials.php'; //database credentials

   //echo DB_USER;
   //die;//exit before html is sent - just want to see connection works!

   // ------ Error Handling ------ //
    define('DEBUG',TRUE); #we want to see all errors
    function myerror($myFile, $myLine, $errorMsg)
    {
        if(defined('DEBUG') && DEBUG)
        {
           echo "Error in file: <b>" . $myFile . "</b> on line: <b>" . $myLine . "</b><br />";
           echo "Error Message: <b>" . $errorMsg . "</b><br />";
           die();
        }else{
            echo "I'm sorry, we have encountered an error.  Would you like to buy some socks?";
            die();
        }
    }

   define ('THIS_PAGE', basename($_SERVER['PHP_SELF']) ); //Constant is UPPERCASED, no dollar sign
   //echo THIS_PAGE;

   $nav1['index.php'] = "Home";
   $nav1['about.php'] = "About";
   $nav1['contact.php'] = "Contact";
   $nav1['samples.php'] = "Samples";
   $nav1['goodies.php'] = "Goodies";

   $heroes = '';//used for randomizer - initialize var
   $planets = '';//used for randomizer - initialize var

   switch(THIS_PAGE)
   {
   //Set most likely scenario as the first to run
   case 'index.php' :
   $title = "Home" ;
   $banner = "Home: Both random() & rotate()";

   $widget01 = randomize($heroes);
   $widget02 = rotate($planets);
   break;

   case 'about.php' :
   $title = "About" ;
   $banner = "About: Only Random()";
   $widget01 = randomize($heroes);
   //$widget02 = rotate($planets);
   break;

   case 'contact.php' :
   $title = "Contact" ;
   $banner = "Contact: Only Random()";
   $widget01 = randomize($heroes);
   //$widget02 = rotate($planets);
   break;


   case 'samples.php' :
   $title = "Samples" ;
   $banner = "Samples: Only Rotate()";
   //$widget01 = randomize($heroes);
   $widget02 = rotate($planets);
   break;

   case 'goodies.php' :
   $title = "Goodies" ;
   $banner = "Goodies: Only Rrotate()";
   //$widget01 = randomize($heroes);
   $widget02 = rotate($planets);
   break;

   case 'template.php' :
   $title = "Template";
   $banner = "Neither random() & rotate()";
   //$widget01 = randomize($heroes);
   //$widget02 = rotate($planets);
   break;

   default :
   $title = "Our Cool Webstie";
   $banner = "Default Banner";
   $widget01 = randomize($heroes);
   $widget02 = rotate($planets);
   break;
   }

   Randomizer() function in 'Config.php':

    function randomize ($arr)
   {//randomize function is called in the right sidebar - an example of random (on page reload)
    if(is_array($arr))
   {//Generate random item from array and return it
    return $arr[mt_rand(0, count($arr) - 1)];
   }else{
    return $arr;
   }
   }#end randomize()
包括“credentials.php”//数据库凭据
//echo DB_用户;
//死亡//在发送html之前退出-只想看到连接工作!
//----错误处理----//
定义('DEBUG',TRUE)#我们希望看到所有的错误
函数myerror($myFile、$myLine、$errorMsg)
{
if(已定义('DEBUG')&&DEBUG)
{
echo“文件中的错误:.$myFile.”行:.$myLine.
; 回显“错误消息:.”$errorMsg.“
”; 模具(); }否则{ echo“对不起,我们遇到了一个错误。您想买一些袜子吗?”; 模具(); } } 定义('THIS_PAGE',basename($_SERVER['PHP_SELF'])//常量大写,无美元符号 //呼应这一页; $nav1['index.php']=“Home”; $nav1['about.php']=“about”; $nav1['contact.php']=“contact”; $nav1['samples.php']=“samples”; $nav1['goodies.php']=“goodies”; $heroes=''//用于随机数发生器-初始化变量 $planets=''//用于随机数发生器-初始化变量 开关(此页面) { //将最有可能的场景设置为第一个运行的场景 案例'index.php': $title=“主页”; $banner=“Home:随机()和旋转()”; $widget01=随机化($heroes); $widget02=旋转($plants); 打破 案例“about.php”: $title=“关于”; $banner=“关于:仅随机()”; $widget01=随机化($heroes); //$widget02=旋转($plants); 打破 案例“contact.php”: $title=“联系人”; $banner=“联系人:仅随机()”; $widget01=随机化($heroes); //$widget02=旋转($plants); 打破 案例“samples.php”: $title=“样本”; $banner=“示例:仅旋转()”; //$widget01=随机化($heroes); $widget02=旋转($plants); 打破 案例“goodies.php”: $title=“糖果”; $banner=“Goodies:Only Rrotate()”; //$widget01=随机化($heroes); $widget02=旋转($plants); 打破 案例“template.php”: $title=“模板”; $banner=“既不是随机的也不是旋转的”; //$widget01=随机化($heroes); //$widget02=旋转($plants); 打破 违约: $title=“我们的酷领带”; $banner=“默认横幅”; $widget01=随机化($heroes); $widget02=旋转($plants); 打破 } “Config.php”中的Randomizer()函数: 函数随机化($arr) {//randomize函数在右侧边栏中被调用-random(页面重新加载)的一个示例 if(is_数组($arr)) {//从数组中生成随机项并返回它 返回$arr[mt_rand(0,计数$arr)-1]; }否则{ 返回$arr; } }#结束随机化()
“header.php”中的代码:

    <h1 class="brand">
    $heros[] = '<img src="img/heroes/coulson.png" />';
    $heros[] = '<img src="img/heroes/fury.png" />';
    $heros[] = '<img src="img/heroes/hulk.png" />';
    $heros[] = '<img src="img/heroes/thor.png" />';
    $heros[] = '<img src="img/heroes/black-widow.png" />';
    $heros[] = '<img src="img/heroes/captain-america.png" />';
    $heros[] = '<img src="img/heroes/machine.png" />';
    $heros[] = '<img src="img/heroes/iron-man.png" />';
    $heros[] = '<img src="img/heroes/loki.png" />';
    $heros[] = '<img src="img/heroes/giant.png" />';
    $heros[] = '<img src="img/heroes/hawkeye.png" />';

    echo randomize($heros);//THis one appears
    echo randomize($widget01); //this one doesn't 
    ?>

     <a href="index.html"><?=$banner?></a></h1>

$heros[]='';
$heros[]='';
$heros[]='';
$heros[]='';
$heros[]='';
$heros[]='';
$heros[]='';
$heros[]='';
$heros[]='';
$heros[]='';
$heros[]='';
回声随机化($heros)//这个出现了
回声随机化($widget01)//这个没有
?>


请注意,我曾尝试在谷歌上搜索答案,并阅读了一些有关堆栈溢出和其他地方的有趣内容,但没有任何我能理解得足够透彻的内容来找出我的问题所在。我是一名新手,仍在努力成为一名业余爱好者

我发现了一个问题,即数组名为“英雄”,但当我称它为“英雄”时,我称它为“英雄”,无“s”。当我在这里输入代码进行检查时,我想我的浏览器的自动更正功能已经修复了它,所以你们这些好人不会看到这个错误,或者我相信所有人都会发现它。

什么是
这个页面
\e:不管用吗。我认为它可以在您的页面上运行,尽管您在示例和商品上遇到了错误。define('THIS_page',basename($_SERVER['PHP_SELF'))//常量大写,无美元符号//呼应此页面;我想我不完全理解你,但是你可以试试下面的方法。回显
随机化($widget01)
得到的内容。对吗?如果不是,你的问题很可能是你的随机化函数,或者更确切地说是你使用的数组。如果是这样,您尝试输出的方式可能是faultyi do echo'randomize($widget01)'。我在“回声随机化($heros);”之后就这么做了它提供了图像,但$widget01没有。