我有以下代码:
<?php
$array1 = array("The price of Mac"=>2000, "One year refundable"=>"Yes", "24/7 support"=>"Yes");
foreach ($array1 as $index => $value) {
if(is_int($value)) {
echo "{$index} is ${$value}, ";
} else {
echo "{$index} is {$value}, ";
}
}
echo "</ br>";
?>
但当我在行中放置一个空格时,$ 2000没有出现
if(is_int($value)) {
echo "{$index} is $ {$value}, ";
}
$ 2000
显示,但如何输出$ 2000?
答案 0 :(得分:7)
echo "{$index} is \${$value}, ";
答案 1 :(得分:2)
使用
echo $index. ' is $'.$value.', ';
或
echo "{$index} is ${$value}, ";
或
echo "{$index} is \${$value}, ";