Jump to content

ThomasNorth

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Posts posted by ThomasNorth

  1. Hi there,

     

    Basic question, but I can't seem to find a page in the PHP docs that answers (though I'm sure such a one exists, I just can't seem to think up the right search terms - anyway)

     

    My question is: is there a short-hand way to use a value from an associative array as the key in another associative array?

     

    So for example, given this array:

     

    $the_array = array(0 => array('name': 'the_name', 'value' : 'the_value'), 1 => etc....);

     

    then this kind of foreach loop doesn't work

     

    $new_data = array();
    foreach($the_array as $element){
    $new_data[$element['name']] = $element['value']; 
    }
    

     

    Obviously I can just save out the values, like $name = $element['name'] --- but I was just wondering if there was a more efficient way to do it?

     

    Cheers,

     

    PS. I tried encapsulating with {} - i.e. $new_data[{$element['name']}] --- but that also fails.

     

×
×
  • 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.