0

I'm new to PHP so this will sound basic to most people but I need to write the code for when a variable returns nothing (blank).

My variable is $winner, but sometimes there is no winner, in this case it just leaves the page blank, I would like it so if there is no winner then it will display "no winner".

This is my attempt:

if empty($winner) {
    echo "no winner";
}
1

2 Answers 2

0

You can make a function to check the variable's valaue with null or empty...

function IsEmptyString($Season){
    return (!isset($Season) || trim($Season)==='');
}

This function can be used to check the same.

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

Comments

0

Just use:

if (!$winner) { // will catch "", null
    echo "no winner"
}

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.