duanjumie8753 2017-10-12 17:43
浏览 311
已采纳

PHP循环遍历嵌套数组以查找特定值,然后获取该数组中获取匹配项的所有元素

I have the following multi dimensional array:

Array
(
[0] => Array
    (
        [name] => Botline
        [description] => Kwese
        [parent_team_id] => 
        [company_id] => 10554
        [id] => 13482
        [external_id] => 13482
        [extras] => 
    )

[1] => Array
    (
        [name] => Books Boutique
        [description] => Kwese
        [parent_team_id] => 
        [company_id] => 10554
        [id] => 13483
        [external_id] => 13483
        [extras] => 
    )

[2] => Array
    (
        [name] => Sij Investments
        [description] => Kwese
        [parent_team_id] => 
        [company_id] => 10554
        [id] => 13484
        [external_id] => 13484
        [extras] => 
    )

[3] => Array
    (
        [name] => Steamcard Investments
        [description] => Kwese installations
        [parent_team_id] => 
        [company_id] => 10554
        [id] => 13549
        [external_id] => 13549
        [extras] => 
    )
)

I want to be able to loop through the array searching for a nested array which has a 'id' equal to lest say '13484'. After I find that 'id' I want to be able to get all the elements in that array and save them.

The number of nested arrays which might come in the main array are undefined so I can not create a predetermined way of getting the right array which has the matching value. How can I achieve this?

  • 写回答

3条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥25 接口/特征方法的异常错误返回如何判断是否需要设计
      • ¥40 代码+预测分析,文件私信发哦(价格可商量)
      • ¥15 GAMES101 HW1 无法定义
      • ¥15 pycharm不管允许什么代码都出错,都会出现下面的情况。
      • ¥15 boost::integrate的用法
      • ¥20 51单片机输出pwm时无法调节频率,如何解决?
      • ¥15 DSP28335 AD采集正弦波
      • ¥50 pwwinauto调式修改
      • ¥30 关于#单片机#的问题:单片机基于51单片机开发计时器,使其实现以下功能:(1)开发板上四个独立按键分别控制计时器的启停、计时器的复位(按下计时值归零)、计时位切换、计时时间的递增
      • ¥15 看个代码。做个详细的解说