Looping Key=>value into an array

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
User avatar
icarpenter
Forum Commoner
Posts: 84
Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England

Looping Key=>value into an array

Post by icarpenter »

Hi

Can anyone help I am trying to loop some values into an array with no success... can anyone help?

I am trying to create...

Code: Select all

$myarray = array( "key1"=>"value1",
                 "key2"=>"value2",
		         "key3"=>"value3",
	             "key4"=>"value4");
But by using a loop to insert the Key=>value information 1 at a time...

If anyone has any ideas i would be most greatful...

Thanks Ian
User avatar
icarpenter
Forum Commoner
Posts: 84
Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England

Looping Key=>value into an array

Post by icarpenter »

It's OK if found the answer by using the following...

Code: Select all

$this->myarray["$key"] = $value;
Rgds Ian
Post Reply