-2

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
                )

        )

)
Gilligan
  • 13
  • 2
  • 1
    Please show what you tried. We'll help you fix your code, but we won't write it for you. – Barmar Dec 17 '18 at 22:14
  • Hint: it should start with `foreach ($array['ring_groups'] as $group)` – Barmar Dec 17 '18 at 22:15
  • See https://stackoverflow.com/questions/6661530/php-multidimensional-array-search-by-value – Barmar Dec 17 '18 at 22:19
  • And https://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php for getting to the nested element in the first place. – Barmar Dec 17 '18 at 22:20
  • @Barmar, thanks for the links, checking those now. I'm totally down for posting code, but my code is a MESS right now with lots of dumb "echo "step 2"" stuff so I can keep track of what is being displayed and not displayed. – Gilligan Dec 17 '18 at 22:52
  • @Barmar, I added my code to the original. Man you guys are feisty! LOL – Gilligan Dec 17 '18 at 23:06
  • What is `current($response["name"])` supposed to mean? The argument to `current()` should be an array, but `$response["name"]` is a string. – Barmar Dec 17 '18 at 23:08
  • Get rid of the `while` loop, and just do `$arrayName = $response["name"];` – Barmar Dec 17 '18 at 23:10
  • You're already looping over the array with `foreach()`, you don't need another loop. – Barmar Dec 17 '18 at 23:10
  • @Barmar, I was trying to pass the array "$response[name]" to the function. :( – Gilligan Dec 17 '18 at 23:16
  • But `$response["name"]` isn't an array. `$response` is an array, `$response["name"]` is a string like `Normal`, `On Call`, etc. – Barmar Dec 17 '18 at 23:17
  • @Barmar, I think I get it. I just wasn't... obviously. :) I've scrapped a lot of that and pushed through with the code below... I'm making some progress. Still uncovering more and more with this puzzle. But I can return the members now... now I just have to pull the forwardings and then match up that ID with the member information so I can actually display useful info. :) – Gilligan Dec 17 '18 at 23:39
  • @Barmar, also, why is this still on "hold"... I did what you asked. – Gilligan Dec 17 '18 at 23:41
  • 5 people have to vote to reopen the question. – Barmar Dec 18 '18 at 00:47

1 Answers1

0

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
    }
  }
}
Mihail Minkov
  • 2,463
  • 2
  • 24
  • 41
  • I have added code to the original post. – Gilligan Dec 17 '18 at 23:07
  • 1
    I see no reason to down vote this answer, in the question there is no detail given about what they need to once members are successfully accessed, @Muihail gets the members and throws that in an array, that answers the question in my opinion. – rs007 Dec 17 '18 at 23:33
  • 2
    @rs007, 100% It helped me get past the roadblock I was on and did it with about 1/10th of the code I was hacking up. I learned a LOT from that... it makes a LOT more sense to do it that way. – Gilligan Dec 17 '18 at 23:40
  • Great stuff @Gilligan, great work so far, post your problem so it's more specific and the work you've accomplished so far, I am positive, we will be able to help you accomplish what you need to – rs007 Dec 17 '18 at 23:50
  • @rs007, is proper etiquette to continue adding here or to add a new post? – Gilligan Dec 18 '18 at 00:10
  • @gilligan I would recommend asking a question, also give this a read https://stackoverflow.com/help/how-to-ask – rs007 Dec 18 '18 at 00:16
  • @Gilligan, apologies I meant new post, – rs007 Dec 18 '18 at 00:19
  • Glad to be of help @Gilligan – Mihail Minkov Dec 18 '18 at 00:30