クラス内でこれを試すことができます
//the search function
function search_array($array, $attr_name, $attr_value) {
foreach ($array as $element) {
if ($element -> $attr_name == $attr_value) {
return TRUE;
}
}
return FALSE;
}
//this function will test the output of the search_array function
function test_Search_array() {
$person1 = new stdClass();
$person1 -> name = 'John';
$person1 -> age = 21;
$person2 = new stdClass();
$person2 -> name = 'Smith';
$person2 -> age = 22;
$test = array($person1, $person2);
//upper/lower case should be the same
$result = $this -> search_array($test, 'name', 'John');
echo json_encode($result);
}