Object Array Iterator

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
montecristo
Forum Newbie
Posts: 20
Joined: Thu Oct 19, 2006 9:51 am

Object Array Iterator

Post by montecristo »

Hi guys,

I have a quick question about storing objects in arrays.

I have a class called customersale, I can store these in an array.

Code: Select all

while ($row = oci_fetch_array ($s, OCI_BOTH)) 
        {
             		 $customersaleid = $row['CUSTOMERSALEID'];
	                 $customersale = new  customersale($customersaleid);
		 echo $customersale->getprice();

		 $customersalearray[$ctr] = $customersale;

		 $ctr =  $ctr + 1;
        }
The class customersale has functions such as getprice(),gettransactiondate() etc....
How do I iterate through this array and retrieve a certain customersale object and apply the class's functions?

Thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

while ($row = oci_fetch_array ($s, OCI_BOTH))
{
   $customersaleid = $row['CUSTOMERSALEID'];
   $customersale = new  customersale($customersaleid);
   $customersalearray[] = $customersale->getprice();
}
Is this what you are after?
montecristo
Forum Newbie
Posts: 20
Joined: Thu Oct 19, 2006 9:51 am

Post by montecristo »

Thank you for getting back to me so quickly!

What I require is to store the customersale objects in an array. So a customer would have one or many customersale objects. I wish to loop through the array containing the customersale objects and then apply the functions to these objects to get the the price, transaction date etc.
montecristo
Forum Newbie
Posts: 20
Joined: Thu Oct 19, 2006 9:51 am

Post by montecristo »

Worked it out
Was doing something stupid :oops:

$customersale = $customersalearray[0];
echo ">>>>>>>>>>>>>" .$customersale->getprice();

This was I was attempting to do.

Thank you for replying
Post Reply