...">

Access to various arrays with similar keys

I have this array

<?php
$themename = "So";
$shortname = "se";

$options = array (
             array( "name" => "the_firstname",
                    "desc" => "The firstname of a person",
                    "id" => $shortname."_the_firstname",
                    "type" => "text",
                    "value" => ""), 

array( "name" => "the_lastname",
       "desc" => "A persons lastname",
       "id" => $shortname."_the_lastname",
       "type" => "text",
       "value" => ""),
     );

foreach($options as $key => $value)
{
   echo $value['id']."<br/>";
}
?>

with similar keys, for example a key id. I would like to access the value idfor the first array.

Doing this echo $value['id'][0]."<br/>";either echo $options['id'][0]."<br/>";does not help.

How can I show the meaning of the first id?

+3
source share
1 answer

echo $options[0]['id'];should do the trick at the top level within the loop forthis should work: $value['id']. You don't need it here [0], as it $valuecontains the first (0) element inside the array $options.

+2
source

All Articles