是否可以在数组中回显变量?我试图通过 PHP 创建 CSS:
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",
)
);
我需要传递一个动态变量,以便它可以显示在索引中。我无法在数组中回显变量。