java to php : arraylists and hashmaps
Posted: Mon Feb 21, 2005 6:56 am
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.
}
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.
}