G
G
Grigory KOVALENKO2018-10-23 13:54:17
Skype
Grigory KOVALENKO, 2018-10-23 13:54:17

Skype? Mobile development?

Is Skype a native or hybrid application?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tiberal, 2018-10-23
@Tiberal

Written in Electron. Is it not noticeable by the lags?

A
Alexey Ukolov, 2015-08-17
@entermix

Because in the first case, you are assigning the result of the comparison in $new_events $order->get_new_events_count('comments') > 0(it can be true or false ).

echo true;  // выведет "1"
echo false; // выведет "" (пустую строку).

Therefore, whatever number the get_new_events_count function returns , if it is greater than 0 , the number 1 will always be displayed .
Do it right like this:
<?php
$new_events = $order->get_new_events_count('comments');
?>
<?php if ($new_events > 0): ?>
    <?= $new_events; ?>
<?php endif; ?>

You could write the same thing like this:
<? if (($new_events = $order->get_new_events_count('comments')) > 0): ?>
    <?= $new_events; ?>
<? endif; ?>

But, as you can see, it is easy to make a mistake in such code. Assignment within a comparison operator is considered bad practice, apart from problems with execution order, it is not uncommon for a developer to write if ($foo = $bar)instead if ($foo == $bar)
of A in the second in if , a normal check is performed, but the get_new_events_count function is called twice, which, apparently, is what you want to avoid.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question