Reputation: 37
i have trouble in codeigneter
when using assignment operators (+=). Please help me.
Here my code in view:
<?php
$t = 220;
$x += $t;
echo $x;
?>
i get the result but in my view there have a error mesage.
A PHP Error was encountered:
Severity: Notice Message: Undefined variable: x
Upvotes: 2
Views: 458
Reputation: 9442
So define it:
<?php
$x = 0;
$t = 220;
$x += $t;
echo $x;
?>
You are telling the code to add to $x a number, this $x is not defined at that point.
Upvotes: 1
Reputation: 59701
$x
is not initialized so just do this:
<?php
$t = 220;
$x = 0;
$x += $t;
echo $x;
?>
Output:
220
Side Note:
You can add error reporting at the top of your file to get error messages (ONLY in testing environment):
<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
?>
Upvotes: 6