Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9117715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:57:42+00:00 2026-06-17T04:57:42+00:00

Not being a coder, I’m trying to do the following and loosing my mind

  • 0

Not being a coder, I’m trying to do the following and loosing my mind trying to do it. I’m sure the answer probably about as basic as they get but I can’t seem to find an answer.

Anyways, here goes.
Have a multidimensional array:

Array
[module 2] => Array
    (
        [1] => SimpleXMLElement Object
            (
                [0] => module 2 EARL outlet temperature
            )

        [2] => SimpleXMLElement Object
            (
                [0] => module 2 inlet temperature
            )
        [15] => SimpleXMLElement Object
            (
                [0] => module 2 EARL inlet temperature
            )

        [19] => SimpleXMLElement Object
            (
                [0] => module 2 outlet temperature
            )

    )

[module 6] => Array
    (
        [3] => SimpleXMLElement Object
            (
                [0] => module 6 EARL inlet temperature
            )

        [4] => SimpleXMLElement Object
            (
                [0] => module 6 asic-4 temperature
            )

        [11] => SimpleXMLElement Object
            (
                [0] => module 6 RP inlet temperature
            )

        [24] => SimpleXMLElement Object
            (
                [0] => module 6 asic-3 temperature
            )

        [25] => SimpleXMLElement Object
            (
                [0] => module 6 inlet temperature
            )

        [26] => SimpleXMLElement Object
            (
                [0] => module 6 EARL outlet temperature
            )

        [28] => SimpleXMLElement Object
            (
                [0] => module 6 outlet temperature
            )

        [30] => SimpleXMLElement Object
            (
                [0] => module 6 RP outlet temperature
            )

    )

What I need is, from each array (module 1, module 2, etc…), return the numeric keys from each of the subarray values. Basically each of the subarray keys corresponds to the key of a another array which contains temperatures to be graphed by rrdtool.

Thanks to someone elses help last night I was able to correctly group the values by “module #” (how I ended up with the array above). But now every time I run through my foreach loops (below) I get the results returned twice.

## Just for testing my foreach loops
foreach ($groupedmods as $modgroupname => $sensorname) {
    foreach ($sensorname as $dsindex => $sensor) {
        if($dsindex != 0) {
        file_put_contents('/usr/local/nagiosxi/var/php.log', print_r($dsindex, true). "\n",     FILE_APPEND);
        }
    }
}
## Draw some graphs
#foreach ($groupedtemps as $modgroupname ) {
#       $ds_name[$dcnt] = "Module Temps Test";
#       $opt[$dcnt] = "--vertical-label \"Temp\" --title \"Module Temps Test \" ";
#
#       foreach ($modgroupname as $dsindex ) {
#               if($dsindex != 0) {
#file_put_contents('/usr/local/nagiosxi/var/php.log', print_r($dsindex, true ). "\n", FILE_APPEND);
#                $def[$dcnt] = "DEF:var$dsindex=$rrdfile:$DS[$dsindex]:AVERAGE " ;
#                $def[$dcnt] .= "LINE2:var$dsindex#F00808:$sensor\"\" " ;
#               }
#       } 
#}

outputs the list of indexes I need two times:

1
2
15
19
3
4
11
24
25
26
28
30
5
16
17
20
21
22
23
29
6
8
7
18
9
31
10
27
12
35
13
32
14
33
34
1
2
15
19
3
4
11
24
25
26
28
30
5
16
17
20
21
22
23
29
6
8
7
18
9
31
10
27
12
35
13
32
14
33
34
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:57:44+00:00Added an answer on June 17, 2026 at 4:57 am

    Not super sure what’s going on with you’re version of PHP (maybe it’s your objects, since I’m not using those), but I use the exact same code and array structure you do and get the same result. Like deceze says, sure you didn’t run the program twice? The file is being used in append mode, so a second run won’t overwrite the first and will just concat onto it.

    If you didn’t run it twice and the code still gives you errors you can use alternate code to just play with the keys. Give this a shot, the functionality should be the same and maybe it will solve your errors (if the above doesn’t):

    $mod_keys = array_keys($groupedmods);
    foreach ($mod_keys as $k) {
      $new_keys = array_keys($groupedmods[$k]);
      foreach ($new_keys as $key) {
        if ($key != 0) {
          file_put_contents('/usr/local/nagiosxi/var/php.log', print_r($key, true)."\n", FILE_APPEND);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder why in the following code, d is not being cons ed into
I have following code that does not work due to a being a value
I see a lot in autoconf code about stuff being dnl'ed and not dnl'ed.
Not being able to find the answer, and also not being able to do
As a coder, and not being a designer, I was wondering if there is
Sorry for the title not really sure how to explain it being that I
jquery.js source code is not being recognised by browser using my page.html served by
When i run this code the paintComponent method is not being called It may
I have a page being ajaxed in, but the document ready code will not
Not being used to php, I'm facing an issue with accessing arrays and its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.