duanqiaoren9975 2012-11-28 04:39
浏览 35

如何回显数组中的变量? [关闭]

Is it possible to echo a variable in an array? Imm trying to create CSS via PHP:

class headerStyle{
    // now  creating our CONSTRUCTOR function
    function __construct($args=array()) {
        $this->fields = array('background','color','fontSize','backgroundUrl','imagePosition','Width','Height','backgroundSize','margin','padding','backgroundRepeat');
        foreach ($this->fields as $field) {
            $this->{"$field"} = $args["$field"];
        }
    }
}


$value = $_POST['mainHeaderBg'];

setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600); 
$var=($_COOKIE["TestCookie"]);
$style = new headerStyle(
       array(
         'background'=>echo $var,
         'color'=>"#F5F3F4",
         'fontSize'=>"24px",
         //backgroundUrl=>"_images/bodyBg1.jpg",
         'backgroundSize'=>"50% 50%",
         'padding'=>"10px 0px 0px 0px",
         'margin'=>"0px 0px 0px 0px",
         'width'=>"100%",
         'height'=>"60px",
         'imagePosition'=>"top-left",
       )
);

I need to pass a dynamic variable so that it can display in index. I'm unable to echo a variable in an array.

  • 写回答

2条回答 默认 最新

  • dsjuimtq920056 2012-11-28 04:51
    关注

    You should change background'=>echo $var to 'background'=> $var

    评论

报告相同问题?