返回元素较少的数组的最短方法


The shortest way to return an array with less elements

我有两个数组。我希望返回包含较少元素的数组。

到目前为止我的代码:

<?php
if ( count($a) < count($b) )
    return $a;
else
    return $b;

提前感谢。

你的方法很好。您可以使用三元?运算符来创建一个较短的if语句,不过:

return (count($a)<count($b)) ? $a : $b;