P
P
polak2282022-03-23 10:14:59
PHP
polak228, 2022-03-23 10:14:59

Is there a way to improve this code?

If you just write $result = $request[$key];, then it will be Warning, which means the absence of $key in $request. Is it really necessary to write like this?

if(array_key_exists($key, $request)) {
    $result = $request[$key];
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2022-03-23
@polak228

you can, but for this you need to know where $request comes from
for all internal variables that are set in the code, the answer is "make the variables always contain all the necessary values."
for variables that come from outside, there are
plus options, this particular code is completely meaningless, it moves the problem one step lower
and now when you access $result there will be the same error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question