Php 过滤数组

Php 过滤数组,php,arrays,class,Php,Arrays,Class,我正在开发一个显示属性的网站。我有一个巨大的XML提要,我把它放入一个数组中 function search_results($department = '', $post_code = '', $min_price = '', $max_price = '', $type = '', $bedrooms = '') { foreach($this->xml->property as $property) { if($property->departme

我正在开发一个显示属性的网站。我有一个巨大的XML提要,我把它放入一个数组中

function search_results($department = '', $post_code = '', $min_price = '', $max_price = '', $type = '', $bedrooms = '') {
    foreach($this->xml->property as $property) {
        if($property->department == $department) {
            $this->properties[] = $property; 
        }
    }
    $this->filter_results();
}
这首先根据部门(如“待售”或“出租”)过滤XML。现在,我希望能够根据通过函数传递的变量搜索这个数组。例如:

if($this->properties->regionID == $post_code) {
    $this->properties[] = $property;
}
但这不起作用。这将在一个名为Results的类中进行。我将如何搜索阵列。我看了一下如何使用array_filter();但是我无法让它工作,当我打印它时,它将返回Array()

有人知道如何搜索/过滤数组吗

这就是我打印时阵列的外观:

数组([0]=>SimpleXMLElement对象([propertyID]=>1[branchID]=>1[clientName]=>Name[branchName]=>branchName]=>branchName[department]=>Lettings[referenceNumber]=>1[addressName]=>4[addressNumber]=>SimpleXMLElement对象()[addressStreet]=>address[address2]=>address2[address3]=>address3[address4]=>SimpleXMLElement对象()[地址邮政编码]=>邮政编码[国家]=>邮政编码[显示地址]=>地址[物业类别]=>1[物业类别]=>1[物业类别]=>0[物业接待室]=>1[物业类别]=>1[显示物业类别]=>公寓/公寓[物业类别]=>2[物业类别]=>16[物业类别]=>0[楼层面积]=>0.00[楼层面积]=>平方英尺[propertyFeature1]=>改建校舍[propertyFeature2]=>市中心位置[propertyFeature3]=>现代装修[propertyFeature4]=>SimpleXMLElement对象()[propertyFeature5]=>SimpleXMLElement对象()[propertyFeature6]=>SimpleXMLElement对象()[propertyFeature7]=>SimpleXMLElement对象()[propertyFeature8]=>SimpleXMLElement对象()[propertyFeature9]=>SimpleXMLElement对象()[propertyFeature10]=>SimpleXMLElement对象()[rent]=>525[rentFrequency]=>1[toLetPOA]=>0[studentProperty]=>SimpleXMLElement对象()[availability]=>2[mainSummary]=>summary.[fullDescription]=>SimpleXMLElement对象()[dateLastModified]=>2014-05-02[featuredProperty]=>0[regionID]=>27[latitude]=>SimpleXMLElement对象()[latitude]=>SimpleXMLElement对象()[flags]=>SimpleXMLElement对象()[image]=>SimpleXMLElement对象([image]=>Array([0]=>image[1]=>image[2]=>image[3]=>image[4]=>image]))

有人知道我如何搜索这个查询吗

$post_code = 43; $min_price = 300; $max_price = 500

等等。

看看代码,我觉得逻辑不错。 不过,有些事情可能会导致这个问题。 在代码的第4行,您有:

$this->properties[] = $property;
这意味着您有一个属性数组

但是,您尝试直接访问对象:

if($this->properties->regionID == $post_code) {
    $this->properties[] = $property;
}
我觉得这很奇怪。您正在尝试查看abject是否具有所需的属性,然后将同一对象保存为数组

因此,我想,一旦您构建了
$this->properties
数组,您只需在其中循环并应用过滤器即可返回一个包含所需内容的属性数组:

foreach($this->properties as $singleProperty) 
{
    if($singleProperty->regionID == $post_code) 
    {
        $this->foundProperties[] = $singleProperty;
    }
}

可能在这里,您可以像这样做一个
打印\r
,这样我们可以更容易地阅读它吗?
echo'';print\r($array);echo'';
?此外,您想要获取的示例-
$post\u code=43;$min\u price=300;$max\u price=500
-似乎不在您正在演示的数组中?