I have two arrays. I wish to return the array containing fewer elements.
My code so far:
<?php
if ( count($a) < count($b) )
return $a;
else
return $b;
Thanks in Advance.
I have two arrays. I wish to return the array containing fewer elements.
My code so far:
<?php
if ( count($a) < count($b) )
return $a;
else
return $b;
Thanks in Advance.
Your way of doing it is fine. You could use the ternary ?
operator to create a shorter if statement though:
return (count($a)<count($b)) ? $a : $b;