homepage Welcome to WebmasterWorld Guest from 54.205.144.54
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Is it possible to reference an associative array key by it's position
Looking for a way to reference variable associative array key names.
growingdigital




msg:4092984
 6:39 pm on Mar 7, 2010 (gmt 0)

Hi Everyone,

Is it possible to refer to an associative array key by the position it was added to the array?

For example, let's say that I have a dynamic result set. I don't know the column names (e.g. associative array key names), but would like to reference the first column or second column numerically.

Is there a built-in function to do this (couldn't find one), or do I need to loop through the keys and assign them to a numerically indexed array.

Let me know if that question makes sense. I always struggle with arrays.

Best,
Jeremy

 

Anyango




msg:4093149
 6:06 am on Mar 8, 2010 (gmt 0)

$myArray=array();
$myArray["firstIndex"]="Hello";
$myArray["secondIndex"]="World";
$myArray["thirdIndex"]="Testing";


any index can still be accessed numerically, like this

echo $myArray[1]; //"World"
echo $myArray[2]; //"Testing"

Same for multidimensional arrays
Sorry if i have not understood the question correctly.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved