0

Here's the instructions: If true, set $price variable to contain the concatenation of a text string (“SALE PRICE:”) and the discounted price calculated by multiplying the regular price by 90%. Concatenated with a <BR /> and a text string (“REG. PRICE:”) and the regular price of the item.

Here's what I've tried:

$price = echo ('SALE PRICE: $' . $discount . 'REG. PRICE: $' . $item->item_cost);

And all I get is "Parse error: syntax error, unexpected T_ECHO"

I've tried googling when to use single and double quotes, but I feel like I'm just interchanging them and not making much of a difference. I saw another thread that was helpful in explaining when to use each type of quote and periods, but I don't think I applied the knowledge properly because I still kept getting an error. Any advice would help.

Lydia
  • 21
  • 3
  • Is $price a javascript variable? I'm assuming not. Why not just `$price = "Sale price: $".$discount... ` and then later `echo $price` – zipzit Dec 19 '15 at 03:13
  • Tip: You're placing the wagon before the horse. `$wagon = echo` ;-) it needs to be the other way around. – Funk Forty Niner Dec 19 '15 at 03:18

2 Answers2

0

echo is not a function in PHP. It is a language construct. You cannot assign its return value. Try without it:

$price = 'SALE PRICE: $' . $discount . 'REG. PRICE: $' . $item->item_cost;
marekful
  • 14,986
  • 6
  • 37
  • 59
  • `echo $price=...` is valid, which is what I feel is what the OP intended to do. – Funk Forty Niner Dec 19 '15 at 03:22
  • You are right, what he probably wanted is to print after concatenating the string. What I sated is that the return value of echo cannot be assigned to a variable as in the example code (because there is no return value). And that stands. – marekful Dec 19 '15 at 03:25
0
$price = 'SALE PRICE: $' . $discount . 'REG. PRICE: $' . $item->item_cost;

echo $price;