-6
if(count($arr1) === count($arr2) === 26)

In the above line it is throwing error

syntax error, unexpected '==='

Why can't i compare the value returned by count() with 26

Mark Evans
  • 974
  • 1
  • 11
  • 29
  • 3
    That's just invalid PHP syntax. You'll have to split up the comparisons and use `&&` – ಠ_ಠ Jun 18 '13 at 12:30
  • -1 because really low quality – hek2mgl Jun 18 '13 at 12:31
  • Well, I think this should have worked. At first, `count($arr2) === 26` should be evaluated to boolean `true` or `false`. Then `count($arr1)` should be (strictly) compared to boolean, giving `false` in any case. So why does this produce error? (I don't mean this makes something different than OP wants, but it should be valid -- I vote up). – Voitcus Jun 18 '13 at 12:33
  • 1
    @hek2mgl it's not low quality, many guys stucked with this http://stackoverflow.com/questions/1075534/cant-use-method-return-value-in-write-context?rq=1 – Mark Evans Jun 18 '13 at 12:38
  • It's **really** low quality and a duplicate as you have shown. Sorry, please don't take it personal. Just try to fix your errors for yourself. If it not works try harder, investigate! but don't ask such questions on SO – hek2mgl Jun 18 '13 at 12:49
  • @Voitcus see the accepted answer – Mark Evans Jun 18 '13 at 12:52
  • @MarkEvans Yes I have, but no syntax error would be if second comparison is in brackets: `if($a == ($b == $c))` has no syntax error (doesn't matter if use `==` or `===`), but in `if($a == $b == $c)` there is one. So the accepted answer is not 100% correct. – Voitcus Jun 18 '13 at 12:55
  • @MarkEvans I don't wanted to be offensive or something like that. I just wanted to say, if you want to get a programmer you'll have to learn to fix such problems for yourself. (Again, not offensive): Use the [manual](http://php.net/docs.php) it is **really** helpful. – hek2mgl Jun 18 '13 at 12:56
  • @hek2mgl I think I really didn't made any efforts to investigate the problem and made some silly mistakes. – Mark Evans Jun 18 '13 at 13:00
  • @MarkEvans Ok. :) However it is not so important anyway. it's just a question on SO (one out of 5 million :) .. You'll learn to fix such problems for yourself, I'm sure.. cu – hek2mgl Jun 18 '13 at 13:03

2 Answers2

4

You can but you have to do it separately:

if(count($arr1) === 26 && count($arr2) === 26)
Bathsheba
  • 231,907
  • 34
  • 361
  • 483
Tobias Golbs
  • 4,586
  • 3
  • 28
  • 49
1

If count($arr2) is 26

if(count($arr1) === count($arr2) === 26)

evaluates to

if(count($arr1) === True)

which would then fail.

You need to perform two logic checks and check they both evaluate to true

davbryn
  • 7,156
  • 2
  • 24
  • 47