【发布时间】:2014-06-16 15:02:31
【问题描述】:
我正在开发一个显示属性的网站。我有一个巨大的 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();但我无法让它工作,当我 print_r 时它会返回 Array()。
有人知道如何搜索/过滤数组吗?
这是我 print_r 时数组的样子:
Array ( [0] => SimpleXMLElement Object ( [propertyID] => 1 [branchID] => 1 [clientName] => Name [branchName] => Branch [department] => Lettings [referenceNumber] => 1 [ addressName] => 4 [addressNumber] => SimpleXMLElement Object () [addressStreet] => address [address2] => address2 [address3] => address3 [address4] => SimpleXMLElement Object () [addressPostcode] => postcode [country] => 邮编 [displayAddress] => 地址 [propertyBedrooms] => 1 [propertyBathrooms] => 1 [propertyEnsuites] => 0 [propertyReceptionRooms] => 1 [propertyKitchens] => 1 [displayPropertyType] => Flat/Apartment [propertyType] => 2 [propertyStyle] => 16 [propertyAge] => 0 [floorArea] => 0.00 [floorAreaUnits] => 平方英尺 [propertyFeature1] => 改建校舍 [propertyFeature2] => 市中心位置 [propertyFeature3] => 现代配件 [propertyFeature4] => SimpleXMLElement Object () [propertyFeature5] => SimpleXMLElement Object () [propertyFeature6] => SimpleXMLElement Object () [propertyFeature7] => SimpleXMLElement Object ( ) [propertyFeature8] => SimpleXMLElement Object ( ) [propertyFeature9] => SimpleXMLElement Object ( ) [propertyFeature10] => SimpleXMLElement Object ( ) [rent] => 525 [rentFrequency] => 1 [toLetPOA] => 0 [studentProperty] => SimpleXMLElement Object () [可用性] => 2 [mainSummary] => 总结。 [fullDescription] => SimpleXMLElement Object () [dateLastModified] => 2014-05-02 [featuredProperty] => 0 [regionID] => 27 [latitude] => SimpleXMLElement Object () [longitude] => SimpleXMLElement Object () [ flags] => SimpleXMLElement Object ( ) [images] => SimpleXMLElement Object ( [image] => Array ( [0] => image [1] => image [2] => image [3] => image [4] => 图片)))
有谁知道我将如何搜索这个查询例如
$post_code = 43; $min_price = 300; $max_price = 500
等等。
【问题讨论】:
-
你能不能像这样写一个
print_r,这样我们可以更容易地阅读它?echo '<pre>'; print_r($array); echo '</pre>';? -
此外,您想要获取的示例——
$post_code = 43; $min_price = 300; $max_price = 500——似乎不在您展示的数组中?