I am using CodeIgniter and trying to set a variable based on a return from a query
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开发者_JAVA百科" to variables. (in this case status = false)
$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
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.
精彩评论