Reading Arrays

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
cyberstryke
Forum Newbie
Posts: 15
Joined: Sun Nov 06, 2005 1:34 pm

Reading Arrays

Post by cyberstryke »

I have an array that I need to parse. basically it contain something like the following:


$my array = array("userName=xxx", "Password=yyy", "affiliateid=1245",.....). ie each element is a string.

the size of the array is undefined so that i dnt know how many elements it contains.

I need to read from this array so that in i get tha values in different variables that I will then use in later in the script.

Ideally i want to do it in such a way so that at the end, i get something like:

$username="xxx";
$password="yyy";
$affiliateid=1245;

Is there any way i can do that so for any array? i meanI dnt know what the array (or array size) will contain.


thanks..
sheila
Forum Commoner
Posts: 98
Joined: Mon Sep 05, 2005 9:52 pm
Location: Texas

Post by sheila »

http://www.php.net/manual/en/language.v ... riable.php

Code: Select all

foreach ($my_array as $value) {
    list($k, $v) = explode('=', $value);
    $$k = $v;
}
Post Reply