array_push and foreach with objects
Posted: Mon Aug 08, 2011 9:56 am
The exact example is to add channels to an array of channels .
The channels sent by JSON and when I got it the following code happens
$TEMPCHANNEL=new Channel();
//input Channels ----------------------------- CNN,BBC,CNBC --------------------------
foreach(FOREACH SYNT)
{
$TEMPCHANNEL->set_logo();
$TEMPCHANNEL->set_type();
$TEMPCHANNEL->set_title();
array_push($CHANNELS,$TEMPCHANNEL);
}
// The Result of CHANNELS array ------------------------- CNBC,CNBC,CNBC ---------------------
I got all the elements with the value of last item entered .
The channels sent by JSON and when I got it the following code happens
$TEMPCHANNEL=new Channel();
//input Channels ----------------------------- CNN,BBC,CNBC --------------------------
foreach(FOREACH SYNT)
{
$TEMPCHANNEL->set_logo();
$TEMPCHANNEL->set_type();
$TEMPCHANNEL->set_title();
array_push($CHANNELS,$TEMPCHANNEL);
}
// The Result of CHANNELS array ------------------------- CNBC,CNBC,CNBC ---------------------
I got all the elements with the value of last item entered .