Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

associative array

Status
Not open for further replies.

neubie

Programmer
Joined
Apr 26, 2001
Messages
1
Location
US
how can i take an array like: array(1, 2, 3, 4)...
and format it to look like this: array(1=>2, 3=>4)?
 
$my_array = array ("1" => "2", "3" => "4");

echo("my_array[1] = $my_array[1]");

prints:
-----
my_array[1] = 2

But be careful with this - associative array elements can either be referenced(I think) by the string keys of the key/value pairs, or by relative positioning in the array. So when you say $my_array[1], are you looking for the value whose string key is 1, or the value of the 2nd element(using relative addressing, the 0 element would be the first, and the 1 element would be the second)?

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top