Reputation: 73
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?
Upvotes: 0
Views: 48
Reputation: 9927
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 )
Upvotes: 1