使用赋值运算符时的未定义变量(+ =)

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

$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);
?>

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.