dsxd62219570
dsxd62219570
2018-12-17 22:12

尝试在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 doutangtan6386 3年前

    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
        }
      }
    }
    
    点赞 评论 复制链接分享