Question: I have an array:

```
$arr_nav = array( array( "id" => "apple", 
          "url" => "apple.html",
          "name" => "My Apple" 
        ),
        array( "id" => "orange", 
          "url" => "orange/oranges.html",
          "name" => "View All Oranges",
        ),
        array( "id" => "pear", 
          "url" => "pear.html",
          "name" => "A Pear"
        )       
 );

```

Which I would like to use a foreach loop to replace (which only allows me to set the number:

```
for ($row = 0; $row < 5; $row++)

```

with the ability to display a `.first` and `.last` class for the relevant array values

**Edit**

I would like the data to be echoed as:

```
<li id="' . $arr_nav[$row]["id"] . '"><a href="' . $v_url_root . $arr_nav[$row]["url"] . '" title="' . $arr_nav[$row]["name"] . '">"' . $arr_nav[$row]["name"] . '</a></li>' . "\r\n";

```

Many thanks for your quick responses. StackOverflow rocks!

Answer: 
```
<?php
$php_multi_array = array("lang"=>"PHP", "type"=>array("c_type"=>"MULTI", "p_type"=>"ARRAY"));

//Iterate through an array declared above

foreach($php_multi_array as $key => $value)
{
    if (!is_array($value))
    {
        echo $key ." => ". $value ."\r\n" ;
    }
    else
    {
       echo $key ." => array( \r\n";

       foreach ($value as $key2 => $value2)
       {
           echo "\t". $key2 ." => ". $value2 ."\r\n";
       }

       echo ")";
    }
}
?>

```

**OUTPUT:**

```
lang => PHP
type => array( 
    c_type => MULTI
    p_type => ARRAY
)

```

**[Reference Source Code](http://phptutors.wordpress.com/2013/04/04/php-arrays-example/)**
If you mean the first and last entry of the array when talking about a.first and a.last, it goes like this:

```
foreach ($arr_nav as $inner_array) {
    echo reset($inner_array); //apple, orange, pear
    echo end($inner_array); //My Apple, View All Oranges, A Pear
}

```

arrays in PHP have an internal pointer which you can manipulate with [reset](http://de.php.net/manual/en/function.reset.php), [next](http://de.php.net/manual/en/function.next.php), [end](http://de.php.net/manual/en/function.end.php). Retrieving keys/values works with [key](http://de.php.net/manual/en/function.key.php) and [current](http://de.php.net/manual/en/function.current.php), but using [each](http://de.php.net/manual/en/function.each.php) might be better in many cases..