如何在php中的echo语句中打印“$”?

时间:2013-05-12 15:38:50

标签: php

我有以下代码:

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

2 个答案:

答案 0 :(得分:7)

echo "{$index} is \${$value}, ";

答案 1 :(得分:2)

使用

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

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

echo "{$index} is \${$value}, ";