Jump to content

Array Question


labmixz

Recommended Posts

I need to find the name of the array element, not the value.

 

What's going on is I am pulling data from a db that has to be sorted a certain way... I wanted the array to look like:

 

$array[$key1][$key2][$x][1]

 

Basically $key1 / $key2 are two unique id's for that unit and then that group within that unit.... while $x is just a standard counter... problem is I don't know the names of $key1 / $key2 and I need to know what they are.

 

I'm sure this is a stupid easy question... just can't think of the solution at the moment.

Link to comment
https://forums.phpfreaks.com/topic/126231-array-question/
Share on other sites

Maybe I didn't explain what I wanted...

 

I already have a foreach looping through everything, that works fine...

 

Here's the array:

$array[$key1][$key2][$x][0]

 

$key1 = random from DB

$key2 = another random from DB

$x = counter

 

getting the info out with a foreach works just fine but I need to know what the name of $key1 is (NOT THE VALUE, but the name of the ARRAY KEY) before I start my loop to get the values...

 

Granted array_keys would work, but I only want to extract that one array key name at that point, not the whole list... and I don't know what the key name COULD be so I can't search for it... because the name of the key is what I need to know to begin with...

 

So basically I know nothing about the array other than how it's setup... I don't know what the first two key are named, just that they are named, I want to know what $array[$key1] is named (not the value, but what the key name is)....

 

Hope that better explains things.

Link to comment
https://forums.phpfreaks.com/topic/126231-array-question/#findComment-652820
Share on other sites

I finally got the information I wanted, I had to create a loop to gather the information and put it into a seperate array when I could easily pull out the names of they elements...

 

 

$x = 0;
foreach($key1 as $key2){
$y = 0;
while (list($key, $val) = each($key1)) {
        $list[$y] = $key;
        $y++;
    }
echo $list[$x];
$x++;
}

 

which lists the name of the element as I'm going through it, which the above is a fairly small portion to what I have and the reasons I needed it are not visable by the above, but I am just glad it's now working.

 

Thanks for the help.

Link to comment
https://forums.phpfreaks.com/topic/126231-array-question/#findComment-652836
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.