how to go through an array without using a pointer?
like looping through arrays in php just like in java iterators?
$i=0
while ($i < $personList.size()-1){
$person = $personList[$i]; // i don't wanna use that. it's just like an average java array. i want it to be something like the java iterator class.
echo $person->getFirstName();
}
i read that foreach is usually used in arrays but what if it's used in user-defined objects?
$p = new Person();
foreach($personList as $person){
$p = $person;
echo $p->getCurrentSalary()."<br>"; //this generates an error. i want to retrieve the objects in the arraylist just as they are.
}
java to php : arraylists and hashmaps
Moderator: General Moderators
-
shibby1011ph
- Forum Newbie
- Posts: 2
- Joined: Mon Feb 21, 2005 6:47 am
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
-
shibby1011ph
- Forum Newbie
- Posts: 2
- Joined: Mon Feb 21, 2005 6:47 am
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$p = null;
foreach($personList as $person)
{
$p =& $person;
$g = $p->getCurrentSalary();
echo $g . '<br />';
}