Hi, I have the following array of objects and I am trying to get it to randomly select one the of the objects from the array, but it only ever seems to return the last object in the array. Anyone have any ideas why and how to fix it: <?php @$obj->Site = 'Site1'; $obj->URL = 'URL1'; $theSite[0] = $obj; $obj->Site = 'Site2'; $obj->URL = 'URL2'; $theSite[1] = $obj; $obj->Site = 'Site3'; $obj->URL = 'URL3'; $theSite[2] = $obj; $counts = count($theSite); $choice = rand (0,$counts-1); echo $theSite[$choice]->Site; ?> Thanks J
i am not familiar with this class/obj thing?? but it works for me by adding unset($obj); after u assign value to the $theSite array. The reason i will think of unset($obj); is because when i print_r() the original array it show all as Site3 and URL3. @$obj->Site = 'Site1'; $obj->URL = 'URL1'; $theSite[0] = $obj; unset($obj); $obj->Site = 'Site2'; $obj->URL = 'URL2'; $theSite[1] = $obj; unset($obj); $obj->Site = 'Site3'; $obj->URL = 'URL3'; $theSite[2] = $obj; unset($obj); $counts = count($theSite); $choice = rand (0,$counts-1); echo $theSite[$choice]->Site; PHP: