dsxd62219570 2018-12-17 22:12
浏览 69
已采纳

尝试在PHP中处理一些嵌套的嵌套数组[关闭]

I've gotten some traction, but there are just TOO MANY for me to wrap my head around.

So... here it is... basically I need to read this array, find the one with the name "On Call". Then I need to display the "members".

Then after that I will have to push that back in, but I can probably figure out how to reverse it if I could figure out how to dig into it to start with.

I've tried foreach, I've tried While loops... I've tried combos of both.

I keep hitting walls and I'm no longer chipping away it seems... please help. edit Seems like I made a Faux Paus by not adding my code, so here it is in all its messy glory. My apologies.

echo "MainArray<br>";
echo count($mainArray);
echo "<br><br>";
foreach($mainArray["ring_groups"] as $response){
    echo "Inside Ring Group Name<br>";
    echo $response["name"];
    while ($arrayName = current($response["name"])) {
        echo $arrayName;
        if ($arrayName == 'On Call') {
   echo "<table style='border: 1px solid #336699; width:500px'>
        <tr>
            <td>On Call Person:</td>
            <td>";
            echo $response["members"];
    echo "</td>
    </table>";
    echo "<br><br>";
    print_r($response["members"]);
    next($response["name"]);
        }
    }
}

/* Display Raw Response */
?>

<pre>
    Did it work?<br>
    <? print_r($response); ?>
    Yo!
</pre>

Here is the data dump (print_r) of the main array:

    Array
(
    [status] => success
    [ring_groups] => Array
        (
            [0] => Array
                (
                    [ring_group] => 25061
                    [name] => Normal
                    [caller_announcement] => 0
                    [music_on_hold] => default
                    [language] => en
                    [members] => account:163768_Adam1,25,0;account:163768_Conf1,25,0;account:163768_Eric1,25,0;account:163768_Fax,25,0;account:163768_FDL1,25,0;account:163768_FDR1,25,0
                    [voicemail] => 637681
                )

            [1] => Array
                (
                    [ring_group] => 25069
                    [name] => Front Desk
                    [caller_announcement] => 0
                    [music_on_hold] => default
                    [language] => en
                    [members] => account:163768_FDL1,25,0;account:163768_FDR1,25,0
                    [voicemail] => 637681
                )

            [2] => Array
                (
                    [ring_group] => 27048
                    [name] => On Call
                    [caller_announcement] => 0
                    [music_on_hold] => default
                    [language] => en
                    [members] => fwd:135888,25,0
                    [voicemail] => 
                )

            [3] => Array
                (
                    [ring_group] => 54169
                    [name] => TenX
                    [caller_announcement] => 0
                    [music_on_hold] => default
                    [language] => en
                    [members] => account:163768_Adam1,25,0;account:163768_Ashleigh,25,0;account:163768_Bryan,25,0;account:163768_Eric1,25,0;account:163768_FDL1,25,0;account:163768_FDR1,25,0
                    [voicemail] => 10
                )

        )

)
  • 写回答

1条回答 默认 最新

  • doutangtan6386 2018-12-17 22:16
    关注

    Perhaps something like:

    foreach($main_array['ring_groups'] as $ring_group) {
      if($ring_group['name'] == 'On Call') {
        $members = explode(";", $ring_group['members'];
    
        foreach($members as $member) {
          // here you do your variable separation as you prefer
        }
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题