views:

33

answers:

2

I am able to use print_r and return this data:

Array ( 
    [array] => Array ( 
        [status] => false 
        [message] => The %s subscription code is out of date. 
    ) 
)

i need to be able to set the elements "status" and "message" to variables. (in this case status = false)

Thanks for the help.

William

+1  A: 

If I understand correctly, you want $status and $message to hold the corresponding values?

$input = array(
    'status' => false,
    'message' => 'The %s subscription code is out of date.'
);

$output = array();
foreach ($input as $key => $value) {
    $$key = $value; // assign $value using variable variable
}

print($status); // prints nothing because it's false
print($message); // The %s subscription code is out of date.
Edward Mazur
+2  A: 
$data = array(
    'status' => 'false',
    'message' => 'The %s subscription code is out of date.'
 );
 extract($data);


 echo $status; // output 'false' because if you status is string.
 echo "<br />";
 echo $message; // output %s subscription code is out of date.

Extract() is a very popular function that converts elements in an array into variables in their own righ

python
Neat! I didn't know about `extract()` - I like your method better.
Edward Mazur