0

I'm new in PHP, so may be I'm wrong (so don't down-vote me) because I'm here for learning.

I'm trying to understand Parse error on Assignment operator.

Example:

<?php
$additon = 2 + 4;
echo "Perform addition: 2 + 4 = " $addition;
?>

Why do I get this error?

Parse error: syntax error, unexpected '$addition' (T_VARIABLE), expecting ',' or ';'

And, why the sum of 6 not showing?

Rasclatt
  • 12,498
  • 3
  • 25
  • 33
Aariba
  • 1,174
  • 5
  • 20
  • 52

2 Answers2

1

You just need to concatenate these two using a dot.

$addition = 2 + 4;
echo "Perform addition: 2 + 4 = ". $addition;

Hope this helps.

Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32
0

With concatenation, the period operator has a higher precedence than both the addition and ternary operators, and so parentheses must be used for the correct behaviour.

<?php
  echo 'Sum: ' . (1 + 2);
?>

From http://php.net/manual/en/function.echo.php

Hope it helps to understand about concatenation.

arshovon
  • 13,270
  • 9
  • 51
  • 69