J
J
jistulamle2018-03-06 14:44:02
PHP
jistulamle, 2018-03-06 14:44:02

How to properly write an IF condition in PHP?

If the condition matches, you need to display the result
$result['error']['code'] = 4, $result['error']['code'] = 16 or no errors should be displayed if no other errors are displayed.

if ($result['error']['code'] == '4' || $result['error']['code'] == '16' || !isset($result['error'])) {
echo ...
}

but it doesn't seem right to me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-03-06
@jistulamle

$codes = [4, 16 ... 125];
if (isset($result['error']) && in_array($result['error']['code'], $codes)) {
     //что-то делаем.
}

The in_array function will suit you. As a result, it will greatly reduce the condition.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question