Var lost in php


I am fairly new to PHP and Yii, and the problem that I am not nor as the question in google, so the only thing I can think of is to ask the question to this list that I have solved many problems.

The issue is as follows: in the code that I attached, I read several records that I keep in array and after the process.

Well, if you look at the debug entries in foreach in he first, all goes well and the variable $items is loaded, but when I get to the second debug $items variable has the correct number of elements, but the elements are empty : count ($items) = 2 but $items[0] and $items[1] are null

foreach ($idiomas as $idioma){
        array('condition'=>'id='.$data->id.' AND idIdioma='.$idioma->id_idioma));
echo "<br>---AAAAAAAAAAA--".$a."-----------<br>";
CVarDumper::dump($items); //in this moment is correct
if (empty($items[$a]) ||$items[$a]==null ){ // not enter because $items have content
    $items[$a]=new TblCategoriastexto();
echo ">>>>>>>>>>>>>>>".count($items) ; //<<<<<<<<<<present 2
CVarDumper::dump($items);              // but in this moment t0 2 are null

for ($a=0;$a<count($items) ;$a++){
echo "<b>".CHtml::encode($nombre[$a]).":</b>";
echo "<br>-----".$a."-----------<br>";
for ($b=1;$b<=20;$b++){
    $out.=$items[$a]->$campo . ",";<<<<<<<<<<<<<<<<error
echo CHtml::encode($out);

This line: if (empty($items[$a]) ||$items[$a]=null ){ will always assign $items[$a] to null.

To compare values, use the comparison (for equality) operator, == instead of the assignment operator =.