R
R
Ruslan Absalyamov2018-04-19 10:05:53
PHP
Ruslan Absalyamov, 2018-04-19 10:05:53

Why is my condition being processed incorrectly?

My script should receive a link without a host, and then the condition is fulfilled, but for some reason the condition is not displayed correctly for me and the first condition always comes out.
Here is my script

public function getPage()
    {
        $uri = $_SERVER['REQUEST_URI'];// Приходит /online/?utm-sources=google_adwords
        if ($uri === '/'){
            $page = ''; // $page = null
        } else {
            $page = preg_replace('/', '', $_SERVER['REQUEST_URI']);
        }
        return $page; //$page = null
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Gavrilovich, 2018-04-19
@nikgavrilovich

=== means equal in value and type
== means equal in value
Otherwise, you are comparing a string with a string, and therefore, even if the strings are not equal, the condition is still met

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question