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

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.

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

Yes, agree with other users that this line need correction

'background'=>echo $var,

Back to debugging,

to get the array content for debugging purpose, put this line anywhere you want to check the array content. It's better to view the result in "view source" mode (like in firefox view source)

print_r($yourArray);