strpos empty/blank substring in string

1.6k views Asked by At

I have a string that is attempting to find specific resources within an API call.

The resources are levels: undergraduate, graduate, independent academic work, and "" (which supposedly means none/unassigned).

So, is simply using strpos($level, "") !== false acceptable when attempting to find the "" level?

I have it set up like so, but any "" level course is not being rendered:

$section = $course->{'SectionName'};
$level = $course->{'Level'};
$parent = the_parent_title();
                if($section === '01' && (
                        strpos($level, $parent) !== false 
                    ||  strpos($level, "") !== false
                    ||  strpos($level, 'Independent Academic Work') !== false
                        )
                        )

Any help would be appreciated.

1

There are 1 answers

0
vaso123 On BEST ANSWER

Two double quotes means an empty string.

Use empty() function of php.

if (empty($level)) {
    //....

Or use string comparison:

if ($level === "") {
    //...