Help with array

LotsOfZeros

^^^ Bi-Winning ^^^
Feb 9, 2008
4,649
118
0
www.makemoniesonline.com
Here is my link structure:
./showities.php?stateid=05

code contained in showcities.php:
Code:
<?php

$stateid = $_GET['stateid'];

$array_state_id[01] = 'AL';
$array_state_id[02] = 'AK';
$array_state_id[03] = 'AZ';
$array_state_id[04] = 'AR';
$array_state_id[05] = 'CA';
$array_state_id[06] = 'CO';
$array_state_id[07] = 'CT';
$array_state_id[08] = 'DE';

$stateabrev = $array_state_id[$stateid];

echo $stateabrev;
?>
It's not echoing the expected value "CA".
I think I did something wrong when I defined the $stateabrev variable.
 


05 is a string, 5 is a number, 05 is interpreted as a number unless quoted.

Eg...

$arr[05] != $arr['05']
$arr[05] == $arr[5]

Without fixing the rest of your code, you could simply do this instead:

$stateabrev = $array_state_id[intval($stateid)];
 
^^ That sounds about right. Why dont you just use 1, 2, 3, 4 rather than 01, 02, 03, 04?
 
using Array the work is very easy. we can also display tabular data using array. In this two, three dimensional array is also available.