Page 1 of 1

Reading Arrays

Posted: Sat Nov 12, 2005 5:59 pm
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..

Posted: Sat Nov 12, 2005 7:23 pm
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;
}