0

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?

1

1 Answer 1

1

You can see from the result that you're getting that with your GetTags() function you're actually echoing #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, returning instead of echoing:

function GetTags() {
    return "#php, #html";
}

$params = array(
    'status' =>GetTags()
);

print_r ($params);

Result

Array ( [status] => #php, #html )

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.