yet another stupid associative array question...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hamr23
Forum Newbie
Posts: 4
Joined: Sun Feb 03, 2008 1:05 am

yet another stupid associative array question...

Post by hamr23 »

Given this situation :

Code: Select all

$parent = array(
     'child' => array(
         'key1' => 'value1',
         'key2' => 'value2'
      ),
      'other' => array(
          'key1' => 'value1',
          'key2' => 'value2'
      )
);
$var = current($parent);
$var would have the 'child' array asigned, right?

Let's say i want to write a function that echoes the key name of given array...

something like:

Code: Select all

echo array_key_name($var);
so this function would output: child

Something tells me that the sollution is just stupid easy... so don't be rude... i'm having a bad day here... my brain isn't working as usual hehe :P

any thoughts?
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: yet another stupid associative array question...

Post by WebbieDave »

The line:

Code: Select all

$var = current($parent);
is equivelant to:

Code: Select all

$var = array('key1' => 'value1', 'key2' => 'value2');
Hence, you cannot deduce the key name "child" from $var.
hamr23
Forum Newbie
Posts: 4
Joined: Sun Feb 03, 2008 1:05 am

Re: yet another stupid associative array question...

Post by hamr23 »

Yeah, that's what i thought... i just had the hope that it was possible...

i guess that dealing with so much OOP it's making me forget how arrays work hahaha...

i would be easier if we could deal with arrays as we can with objects... something like, array->parent->key()

hehe... silly me.


Thanks anyway :D
Post Reply