Page 1 of 1

yet another stupid associative array question...

Posted: Fri Jun 13, 2008 2:27 pm
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?

Re: yet another stupid associative array question...

Posted: Fri Jun 13, 2008 2:45 pm
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.

Re: yet another stupid associative array question...

Posted: Fri Jun 13, 2008 2:53 pm
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