Why this array is not working?


         		

$t = count($sendReceiveAR);       		

$pk = array();                       		

for ($i = 0; $i <=$t; $i++)

{              	

        $pk[$i] = $sendReceiveAR[$i]->primaryKey(); 		

}       		

InvoiceMeta::model()->findAllByPk($pk);



I want to copy part of the PK if AR array to another array. Sound simple, but I just couldn’t get it work. Please help!!

The error message is


Undefined offset: 2	

Thank you!

what are the values of $sendReceiveAR ?

seem like it does not have the index 2… this can happen if the array is associative…

for this is better to use foreach() loop… instead of for()

Also, in a for loop starting from the 0 indexed value, you should use less then sign (<) not less then or equal (<=), meaning:




$t = count($sendReceiveAR);                     

$pk = array();                                  

for ($i=0; $i<$t;$i++)

{               

        $pk[$i] = $sendReceiveAR[$i]->primaryKey();             

}                       

InvoiceMeta::model()->findAllByPk($pk);



I see. That’s the problem. Thank you!