variable as array...get the data inside one

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Next_Gate
Forum Newbie
Posts: 15
Joined: Fri Dec 20, 2002 4:54 pm

variable as array...get the data inside one

Post by Next_Gate »

I have this code in a file:

Code: Select all

$var = array ( 
     'varName1'  =>  "Hello Wolrd 1",
     'varName2'  =>  "Hello Wolrd 2",
     'varName3'  =>  "Hello Wolrd 3"
)
So i know that i can call the variable $var like this:

Code: Select all

$string = $varї'varName1']
but i need to know if its possible to call it by position.. for example varName1 = 0
varName2 = 1
varName3 = 2

bu t i have trie to do this and doesnt work $string = $var[0]

and the variable string doesnt take anything....

Any of you could help me please??

Thanks
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Change $string = $var[0] to $string = $var['0'] and see if that works.

John M
Next_Gate
Forum Newbie
Posts: 15
Joined: Fri Dec 20, 2002 4:54 pm

Post by Next_Gate »

already done.. with this:

Code: Select all

$newArray = array_values($array);
then you invoque like this:

Code: Select all

$newArrayїnumericValue]
Thats it.. it was much easier that i thought!!..ajja
Post Reply