I am trying to set array 'status' as function results
<?php function GetTags(){ echo "#php, #html"; } $params = array( 'status' =>GetTags() ); print_r ($params);
I need array 'status' to be "#php, #html" Tried a lot of combination with " and ' but without any success What I am missing here, anybody to help me?
You can see from the result that you're getting that with your GetTags()
function you're actually echo
ing #php, #html
(which doesn't return anything so you get an empty string in the value). What you need to do is return
it from the function so it will be added as status
' value.
Your way:
function GetTags() {
echo "#php, #html";
}
$params = array(
'status' =>GetTags()
);
print_r ($params);
Result
#php, #htmlArray ( [status] => )
Notice how the text is first printed on the screen, and then you get no value in status
?
Now, return
ing instead of echo
ing:
function GetTags() {
return "#php, #html";
}
$params = array(
'status' =>GetTags()
);
print_r ($params);
Result
Array ( [status] => #php, #html )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.