Multiply a character string by a number

后端 未结 1 1423
梦如初夏
梦如初夏 2021-01-29 08:28

I want to display a fraction in PHP. For that I wrote:

$a = 3; 

$b = 2;

$c = \"$a/$b\";

echo $c; // this displays 3/2
but on the other hand I want to multipl         


        
1条回答
  •  北恋
    北恋 (楼主)
    2021-01-29 08:53

    Try change single quotes into double quotes. Of without quotes, depend what you expect. Then try change type of $c.

    Example:

    $a = 3;
    $b = 2;
    $c = "$a/$b"; // or $c = $a/$b;
    echo $c; // this displays 3/2
    // but on the other hand I want to multiply $c by an integer;
    echo (float)$c * 2; // this shows me an error
    

    0 讨论(0)
提交回复
热议问题