首页 > 解决方案 > PHP用empty()或truthy检查变量

问题描述

谁能告诉我在 if 语句中使用 empty() 函数或“truthy”检查变量是否具有值之间的区别?据我所知,他们实现了同样的目标?.. 我正在为 Wordress 编写一个函数,该函数循环遍历分类法并且两者都可以工作,但我不确定哪个是最好的。

   $taxonomies = get_taxonomies($args, $output, $operator);

      if (!empty($taxonomies)) {

      ...code here

    }

或者

$taxonomies = get_taxonomies($args, $output, $operator);

  if ($taxonomies) {

...code here

}

标签: php

解决方案


推荐阅读