I have an array of custom objects and I want to find the objects who have matching property values.
This is my object.php:
class game_list
{
var $team_name;
var $field_nr;
var $time;
/**
* @return mixed
*/
public function getTeamName()
{
return $this->team_name;
}
/**
* @param mixed $team_name
*/
public function setTeamName($team_name)
{
$this->team_name = $team_name;
}
/**
* @return mixed
*/
public function getFieldNr()
{
return $this->field_nr;
}
/**
* @param mixed $field_nr
*/
public function setFieldNr($field_nr)
{
$this->field_nr = $field_nr;
}
/**
* @return mixed
*/
public function getTime()
{
return $this->time;
}
/**
* @param mixed $time
*/
public function setTime($time)
{
$this->time = $time;
}
}
So I have an array with x number of these objects. I want to find objects which have the same $field_nr and $time values. For example:
If two objects on my array, X and Y, both have $field_nr = 1 and $time = "12:00" I want to print out "Match!".
This is what I am doing currently:
//getPlaySchedule returns my array($feedback) of objects
$feedback= getPlaySchedule($cup_name, $cup_year, $division);
for($x=0; $x<count($feedback); $x++){
$time = $feedback[$x]->getTime();
$field = $feedback[$x]->getFieldNr();
$team = $feedback[$x]->getTeamName();
for($y=0; $y<count($feedback); $y++){
if($time == $feedback[$y]->getTime() && $field == $feedback[$y]->getFieldNr() && $team != $feedback[$y]->getTeamName()){
echo 'Match!';
}
}
}
My solution, however, prints out "Match!" two times for each match. Is there a better way of finding these matches in my object array?
Marcus