Multi dimensional array?

I made this simple php script to display an image, and its alt attribute, I simply creased an array of the building numbers and echoed an image based on what in $id (which is either 0-8 (the array key))


<?php
$id = $_GET['id'];
$maps = array (
    1720,
    1730,
    1750,
    1770,
    1760,
    1780,
    1810,
    1820,
    1830
);
if (id==0)
echo '<img src="/images/map-'.$maps[0].'.jpg" alt="La Sierra">';
elseif (id==1)
echo '<img src="/images/map-'.$maps[1].'.jpg" alt="Cabrillo">';
elseif (id==2)
echo '<img src="/images/map-'.$maps[2].'.jpg" alt="La Princessa">';
elseif (id==3)
echo '<img src="/images/map-'.$maps[3].'.jpg" alt="Las Flores">';
elseif (id==4)
echo '<img src="/images/map-'.$maps[4].'.jpg" alt="La Playa">';
elseif (id==5)
echo '<img src="/images/map-'.$maps[5].'.jpg" alt="La Perla">';
elseif (id==6)
echo '<img src="/images/map-'.$maps[6].'.jpg" alt="El Encanto">';
elseif (id==5)
echo '<img src="/images/map-'.$maps[7].'.jpg" alt="El Mirador">';
else
echo '<img src="/images/map-'.$maps[8].'.jpg" alt="El Camino">';
?>

I was thinking, theres got to be a better way to do this (two dimensional arrays) to hold both the alt thing (building name) and the #…
Can you show me how to do that?

Thx.

Something like this?

<?php
$id = (int)$_GET['id'];
$maps = array (
    array('map' => 1720, 'alt' => 'La Sierra'),
    array('map' => 1730, 'alt' => 'Cabrillo'),
    array('map' => 1750, 'alt' => 'La Princessa'),
    array('map' => 1770, 'alt' => 'Las Flores'),
    array('map' => 1760, 'alt' => 'La Playa'),
    array('map' => 1780, 'alt' => 'La Perla'),
    array('map' => 1810, 'alt' => 'El Encanto'),
    array('map' => 1820, 'alt' => 'El Mirador'),
    array('map' => 1830, 'alt' => 'El Camino')
);

echo '<img src="/images/map-'.$maps[$id]['map'].'.jpg" alt="'.htmlentities($maps[$id]['alt']).'">';
?>

You could also add some checks to see if the ID being entered into the URI actually exists in the array:


<?php

$maps = array(
    array(1720, 'La Sierra'),
    array(1730, 'Cabrillo'),
    array(1750, 'La Princessa'),
    array(1770, 'Las Flores'),
    array(1760, 'La Playa'),
    array(1780, 'La Perla'),
    array(1810, 'El Encanto'),
    array(1820, 'El Mirador'),
    array(1830, 'El Camino')
);

if(isset($_GET['id']))
{
	$id = (int) $_GET['id'];
	if(!array_key_exists($id, $maps))
	{
		$id = 0;
	}
}
else
{
	$id = 0;
}

echo '<img src="/images/map-',$maps[$id][0],'.jpg" alt="',$maps[$id][1],'">';

?>

thsnk you