Short ciruit question is asked already I know. But i want to know why it dont work here. Does short circuit has some effects due to parallel processing or pipelining.
I faced very strange situation with my code. The code looks like this
foreach($feeds as $k=>$feed)
{
foreach($filtered as $item)
{
if(($feed['object'] == $item['object']) && (($feed['time']-$item['time'])<10))
{
Code....
}
}
}
When i put both condition just like above in same If()
block they both get compared.
But when i put them in nested blocks they take much lesser time to excute.
Question: Does && work as a short circuit operator. Which mean
if $feed['object'] == $item['object']
fails
($feed['time']-$item['time'] < FEED_TIME)
will not be evaluated.
It looks like PHP evaluate cond2
even when cond1
failed.
Can you explain how && actually works in PHP.
Benchmarks
With code as above the if execute for approx 61000 time. taking 27 sec to execute for whole website.
With nested conditions approx 10000 executions for condtion2
$feeds
are about 1700 entries where $filtered
is 392 entries.
Thanks