0

我有以下代码:

<?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美元?

4

2 回答 2

7
echo "{$index} is \${$value}, ";
于 2013-05-12T15:40:12.003 回答
2

利用

echo $index. ' is $'.$value.', ';

或者

echo "{$index} is &#36;{$value}, ";

或者

echo "{$index} is \${$value}, ";
于 2013-05-12T15:42:20.523 回答