我可以使用print_r并返回此数据:
Array (
[array] => Array (
[status] => false
[message] => The %s subscription code is out of date.
)
)
我需要能够将元素“status”和“message”设置为变量。 (在这种情况下,status = false)
答案 0 :(得分:2)
$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()是一个非常流行的函数,可以将数组中的元素转换为自己的变量
答案 1 :(得分:1)
如果我理解正确,您希望$status
和$message
保留相应的值吗?
$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.