按公共ID过滤PHP对象数组
我在一个物业网站上工作,这从CRM数据库中拉出结果。拉回的结果是基于较大房产(即容纳各种公寓的一个大街区)内的可用单元。我需要能够按属性但不是按单元推送图像数组,但结果数组返回每个属性和每个单元。我的意思是:
Array
(
[0] => stdClass Object
(
[property_id] => 2
[unit_id] => 5
[property_name] => Morb House
[address] => 123 Test Street, Blahtown, BL1 AHH
[unit_name] => Apartment Number 1
[max_guests] => 2
[description] => This is a nice place
[bedrooms] => 1
)
[1] => stdClass Object
(
[property_id] => 2
[unit_id] => 6
[property_name] => Morb House
[address] => Some Road, Some Town, Anywhere
[unit_name] => Apartment Number 2
[max_guests] => 4
[description] => This is a slightly bigger place
[bedrooms] => 2
)
[2] => stdClass Object
(
[property_id] => 2
[unit_id] => 11
[property_name] => Morb House
[address] => 123 Test Street, Blahtown, BL1 AHH
[unit_name] => Cool Studio
[max_guests] => 1
[description] => This is a teeny weeny place
[bedrooms] => 1
)
[3] => stdClass Object
(
[property_id] => 4
[unit_id] => 12
[property_name] => Fake Buildings
[address] => 1 Fake Street, Anytown
[unit_name] => Fake Apartment One
[max_guests] => 1
[description] => Some description here
[bedrooms] => 1
)
)
我将从另一个表获取的图像将通过属性ID进行过滤,我打算将其添加到与该属性相关的对象中。但是,由于在单个属性中有多个单位可供预订,因此该属性ID在前3个结果中重复。理想情况下,我希望我的结果如下所示:
Array
(
[2] => stdClass Object
(
[property_id] => 2
[property_name] => Morb House
[address] => 123 Test Street, Blahtown, BL1 AHH
[units] => Array
(
[5] => stdClass Object
(
[unit_name] => Apartment Number 1
[max_guests] => 2
[description] => This is a nice place
[bedrooms] => 1
)
[6] => stdClass Object
(
[unit_name] => Apartment Number 2
[max_guests] => 4
[description] => This is a slightly bigger place
[bedrooms] => 2
)
[11] => stdClass Object
(
[unit_name] => Cool Studio
[max_guests] => 1
[description] => This is a teeny weeny place
[bedrooms] => 1
)
)
)
[4] => stdClass Object
(
[property_id] => 4
[property_name] => Fake Buildings
[address] => 1 Fake Street, Anytown
[units] => Array
(
[12] => stdClass Object
(
[unit_name] => Fake Apartment One
[max_guests] => 1
[description] => Some description here
[bedrooms] => 1
)
)
)
)
其中键实际上是属性is,并且该属性中的每个单元都有一个子对象,以相关单元is为关键字。
我只需要一些关于如何在PHP中做到这一点简单和干净的建议。
转载请注明出处:http://www.sdxiangshi.com/article/20230330/2485990.html
随机推荐
-
按同一字段的多个值过滤
我有以下模型,ViewSet和FilterSet。class Contact(models.Model): PERSON = PERSON ORGANIZATION = ORGANIZATION COMPANY = ...
-
按Liquid标记中对象内的datetime属性排序列表
我正在尝试对Freshdesk上特定文件夹上的最新文章进行排序。据我所知,这篇文章有一个created_on“属性,它是”date/time“类型的(请参阅article.created_on”https://support.freshde...
-
按日期对具有日期字段的对象数组进行排序
给定以下对象数组,我需要按日期字段升序对它们进行排序。var myArray = [ { name: Joe Blow, date: Mon Oct 31 2016 00:00:00 GMT-0700 (PDT) }...
-
按对象键进行Firestore查询
我在firestore中的一个集合中有一系列嵌套对象,它们都有一个UID键。我想要查询与某个用户相关的所有文档,方法是检查它们的UID是否为对象键(基本上是它是否存在)。这是firestore中的模型:?这就是我目前尝试返回文档的方式: ...
-
按月筛选产品数组
我正在做一个vue项目,我有一个在数组中有数组的json。我想做一个月份的过滤器,根据我选择的月份来显示带有该过滤器的产品列表我有一个有几个月(6,12,18)的选择器,我怎么才能只显示我用选择器选择的产品呢?? [ { ...
-
按其他列表过滤列表系列
我想按列表过滤一系列列表。下面我介绍了一个MWE:a = np.array([[0,1,2],[2,3,5]]) b = pd.Series(list(a))复制所需输出为0 [0,1,2]复制我试过了b[b == [1, 2, 3]] #...
-
按列计算两个数组的最大值,并计算一个数组具有最大值的次数
我有两个np数组:a1 = np.array([1, -1]) a2 = np.array([3.7416574e-04, -7.7873659e-01])复制我想按列计算a1保持最大值的次数。我以列的方式计算最大值:np.maximum(...
-
按关键点计算对象数组(动态)上的百分比
我有下面的javascript对象数组。如果到达任何新的status密钥,则数组的大小可能会有所不同。[ {status:init,count:1000}, {status:start,count:2500}, {s...
-
按另一个相关值对javascript数组进行排序
我遇到了根据需要对数组进行排序的挑战;下面是我的代码:callbacks : { onComplete : function(id, filename, response) { ...
-
按子字符串值过滤RDD
我想根据分析子字符串中的值从RDD[(String,List[(String,String,String,String)]中过滤出一些条目:这是我的样本数据:(600,List((600,111,1,1), (615,111,1,5))) ...