I managed to get it working. I think it was a matter of me not understanding how ForEach works, so I opted for a normal For loop and it worked.
This is some of the working code if it would help anyone.
Thanks a bunch!! ;D
[php]class Competitor{
var $name;
var $country;
var $event;
var $medal;
var $WR;
//constructor requires 5 values eg; Lee Chong Wei, Malaysia, Badminton, N, S
//medal is either G, S or B
function __construct($name, $country, $event, $medal, $WR){
$this->name = $name;
$this->country = $country;
$this->event = $event;
$this->WR = strtoupper($WR);
$this->medal = strtoupper($medal);
}
function getName(){ //returns competitor name
return $this->name;
}
function getCountry(){ //returns competitor's country
return $this->country;
}[/php]
[php]$competitorArray = array();
for ($i=0; $i<$arraySize; $i++){
//bunch of code
$competitorArray[] = new Competitor($compName, $compCountry, $compEvent, $compMedal, $compWR);
}[/php]
[php]for ($i=0; $i<$countryArraySize; $i++)
{
?>
<?php print $countryArray[$i]->getcName(); ?> |
<?php print $countryArray[$i]->getTotalMedals(); ?> |
<?php
}
?>[/php]