Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP中的数组数生成if语句?_Php_Arrays_If Statement - Fatal编程技术网

如何使用PHP中的数组数生成if语句?

如何使用PHP中的数组数生成if语句?,php,arrays,if-statement,Php,Arrays,If Statement,函数的作用是:查找数组。可能有一个或多个数组 现在我想让if语句取决于数组的数目 如何使用数组的数目生成if语句 function findParent($order_id){ ... $Q = $this->db->get('omc_order_item'); if ($Q->num_rows() > 0){ foreach ($Q->result_array() as $row){

函数的作用是:查找数组。可能有一个或多个数组

现在我想让if语句取决于数组的数目

如何使用数组的数目生成if语句

function findParent($order_id){

  ...
  $Q = $this->db->get('omc_order_item');
        if ($Q->num_rows() > 0){
            foreach ($Q->result_array() as $row){
                $data[] = $row;
            }
        }
   ... 
   return $data; 

 }
我试过这个,但不起作用

function deleteitem($order_id){
    $childless = $this->MOrders->findParent($order_id);
    if ($childless<2){
        $data['childlessorder']= $this->MOrders->findParent($order_id);
...
函数deleteitem($order\u id){
$childless=$this->MOrders->findParent($order\u id);
如果($childlessorders->findParent($order\u id);
...
它必须检查$childless是否小于2


我如何更改它,以便它检查数组的数量是否为1(可以小于2,不是吗?

如果您指的是数组的数量,那么

if (count($childless) < 2)
将输出2


有关文档,请参见该页。

我相信您要查找的是
count()
函数。您向它传递一个数组,它将返回数组中的元素数。请参见:
$childless包含大量信息,而不仅仅是行数,您需要从$childless提取行计数。
例如,如果(count($childless)<2)

echo count(
    array(
        0 => array(1,2),
        1 => array(3,4)
    )
);