开发者

I am using CodeIgniter and trying to set a variable based on a return from a query

开发者 https://www.devze.com 2023-01-12 13:04 出处:网络
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 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.
0

精彩评论

暂无评论...
验证码 换一张
取 消