双精度 $(变量的变量)不会将变量值打印为变量


double $ (variable of variable) doesn't print the variable value as a variable

我有以下代码:

<?php
$dates = array('2014-12-01','2014-12-02','2014-12-08','2014-12-09','2014-12-10','2014-12-11');
$values = array(5,3,7,8,9,2);
foreach ($dates as $date){
 //Array of the regarded days names is generated
  $days[] = strtolower(date('l', strtotime($date)))."'n";
}
for ($i = 0; $i < count($days); $i++){
 $day = $days[$i];    
 $$day = $values[$i];
}    
echo $monday;
?>

echo $monday不打印任何值,我希望它打印 8,因为在最后一个循环中,我有一个以 $day 值命名的变量,该值的最后一个设置应该是 8。那么为什么它设置不正确?!

这是一个演示:http://codepad.org/VDIyBuq3

这是你的问题:

$days[] = strtolower(date('l', strtotime($date)))."'n";
                                                 ^^^^^ here
您将在值

的末尾添加一个换行符,因此您的值不会monday而是monday'n

只需删除它:

$days[] = strtolower(date('l', strtotime($date)));