How to check if variable is array?… or something array-like

后端 未结 6 1677
南方客
南方客 2020-12-04 22:46

I want to use a foreach loop with a variable, but this variable can be many different types, NULL for example.

So before foreach

6条回答
  •  暖寄归人
    2020-12-04 23:46

    Functions

     0) {
        if (!isset($array[--$i])) {
          return true;
        }
      }
      return false;
    }
    

    Example

     'bar' ];
    
    var_dump(isAssociative($arr));
    # bool(false)
    
    var_dump(isAssociative($obj));
    # bool(true)
    
    var_dump(isArray($obj));
    # bool(false)
    
    var_dump(isArray($arr));
    # bool(true)
    

提交回复
热议问题