php 檢查數組為空_檢查數組是否為空在PHP中

php 檢查數組為空

Given an array and we have to check if array is an empty or not using PHP.

給定一個數組,我們必須檢查數組是否為空或不使用PHP。

To check whether an array is empty or not, we can use a built-in function empty(), in other cases where we want to check if a given variable is empty or not, it can also be used. It returns a Boolean response based on the condition that if the given variable contains a non-empty, non-zero value then it returns "false" otherwise, it returns "true".

要檢查數組是否為空 ,我們可以使用內置函數empty() ,在其他情況下,如果要檢查給定變量是否為空,也可以使用它。 它基于以下條件返回布爾響應:如果給定變量包含非空,非零值,則返回“ false”,否則返回“ true”。

Syntax:

句法:

    empty ($var);
empty ($array);

PHP code:

PHP代碼:

<?php
// array declaration
$array1 = array('hello', 'world');
$array2 = array();
//checking whether arrays are empty or not
if (empty($array1)) {
echo "array1 is empty\n";
} else {
echo "array1 is not empty\n";
}
if (empty($array2)) {
echo "array2 is empty\n";
} else {
echo "array2 is not empty\n";
}
?>

Output

輸出量

array1 is not empty
array2 is empty

翻譯自: https://www.includehelp.com/php/check-if-an-array-is-empty-or-not-in-php.aspx

php 檢查數組為空

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541271.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541271.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541271.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

JEESZ分布式架構3--CentOs下安裝MySQL(環境準備)

聲明&#xff1a;因為運行環境是基于Linux系統的&#xff0c;在做此框架之前需要做一些前期的環境準備工作CentOs下安裝MySQL網上很多實例&#xff0c;因為博客后期作為框架的原生教程&#xff0c;故這邊做詳細的安裝記錄&#xff0c;我這邊已經下載好了MySQL&#xff0c;通過s…

一個函數里兩個setjmp_C語言中setjmp.h的longjmp()函數

一個函數里兩個setjmpWe can call this function as an advance version of goto statement but with more dynamic range. The longjump() function allows us to pass parameters to know that the control has been jumped or not. 我們可以將此函數稱為goto語句的高級版本&…

linux sublime nodejs,Ubuntu環境下sublime3 nodejs安裝與插件配置

1.sudo add-apt-repository ppa:webupd8team/sublime-text-3回車&#xff0c;出現很多信息。但是我們看看圖片最后字知道&#xff0c;這地方在等待我們確認是否添加這個倉庫&#xff0c;按enter鍵繼續&#xff0c;按crtlc取消。此時&#xff0c;按ENTER繼續&#xff0c;建立信任…

李洪強iOS開發之FMDB線程安全的用法

// // ViewController.m // 04 - FMDB線程安全的用法 // // Created by 李洪強 on 2017/6/6. // Copyright © 2017年 李洪強. All rights reserved. // #import "ViewController.h" //導入頭文件 #import "FMDB.h" interface ViewController () p…

SCHAR_MIN常數,C ++中的示例

C SCHAR_MIN宏常量 (C SCHAR_MIN macro constant) SCHAR_MIN constant is a macro constant which is defied in climits header, it is used to get the minimum value of a signed char object, it returns the minimum value that a signed char object can store, which i…

android分開兩個線程做事,android開發教程之handle實現多線程和異步處理

這次淺談一下Handler,為什么會出現Handler這個功能特性呢&#xff1f;首先&#xff0c;在之前的基本控件&#xff0c;基本都是在Activity的onCreate(Bundle savedInstanceState)方法中調用和處理的&#xff0c;但是&#xff0c;在有些情況&#xff0c;比如在網絡上下載軟件等一…

夏夜

兒時的夏夜畢竟是最有夏夜的味道。屋堂的煤油燈啪嗒的跳動&#xff0c;忽明忽暗&#xff0c;真怕它脆弱的明亮突然變黑暗。屋外彎月星稀&#xff0c;月光優雅的撒在平靜的湖面上&#xff0c;清純而又溫和。水鳥在湖岸邊慵懶的伸了伸脖子。正享受著夏夜的寧靜和清涼。調皮的小孩…

Python operator.lt()函數與示例

operator.lt()函數 (operator.lt() Function) operator.lt() function is a library function of operator module, it is used to perform "less than operation" on two values and returns True if the first value is less than the second value, False, otherw…

android實現滑動切換圖,Android:使用ViewPager實現左右滑動切換圖片加點點

圖片發自簡書App1、引入android-support-v4.jar包&#xff0c;在主布局里加入< ?xml version"1.0" encoding"utf-8"?>< RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:tools"http://schemas.…

div的替代品

人們在標簽使用中最常見到的錯誤之一就是隨意將HTML5的<section>等價于<div>——具體地說&#xff0c;就是直接用作替代品(用于樣式)。在XHTML或者HTML4中&#xff0c;我們常看到這樣的代碼&#xff1a; <!-- HTML 4-style code --> <div id"wrapper…

threadgroup_Java ThreadGroup list()方法與示例

threadgroupThreadGroup類的list()方法 (ThreadGroup Class list() method) list() method is available in java.lang package. list()方法在java.lang包中可用。 list() method is used to list or display information (like name, priority, thread group, etc.) to the st…

html的柱狀圖去除右邊縱坐標,excel如何把次坐標軸逆序

excel2010設置水平坐標軸逆序類型,但垂直坐標軸刻設置水平坐標軸逆序且垂直坐標軸軸仍位于圖表左側的步驟是&#xff1a;打開帶有圖表的Excel工作表&#xff1b;在圖表區域的水平軸標簽位置雙擊鼠標左鍵&#xff0c;打開“設置坐標軸格式”&#xff1b;勾尋逆序類別”&#xff…

jhipster項目遷移websocket

2019獨角獸企業重金招聘Python工程師標準>>> 1、 在項目目錄下命令行安裝 兩個組件 bower install sockjs-client bower install stomp-websocket 2、在index.html 中加入組件js的引用 <script src"bower_components/sockjs-client/dist/sockjs.js">…

Java包hashCode()方法及示例

包類hashCode()方法 (Package Class hashCode() method) hashCode() method is available in java.lang package. hashCode()方法在java.lang包中可用。 hashCode() method is used to return the hashcode of the package calculated from the package name. hashCode()方法用…

html 圖片上放置按鈕,用CSS在圖片上再加一個小按鈕

很簡單的&#xff0c;嗯&#xff0c;就是要做成這樣的&#xff1a;用CSS&#xff0c;當然得用層了&#xff0c;就是在圖片上再加一個層&#xff0c;用來放那個按鈕&#xff0c;按鈕又有兩種方式可以放&#xff0c;一種是直接用圖片img標簽&#xff0c;一種是通過背景圖片放上去…

html點擊導航變色,點擊導航后,當前導航的顏色變色

html>Documentnav ul {padding: 0;list-style: none;}nav ul li {text-decoration: none;width: 70px;line-height: 50px;text-align: center;float: left;background-color: #000;color: #fff;cursor: pointer;}.gray {background-color: rgba(0,0,0,0.6);}首頁實戰路徑猿問…

Java掃描儀toString()方法及示例

掃描儀類toString()方法 (Scanner Class toString() method) toString() method is available in java.util package. toString()方法在java.util包中可用。 toString() method is used to string denotation of this Scanner and it contains information related to tracing.…

怎么將oracle的sql文件轉換成mysql的sql文件

怎么將sql文件導入PowerDesigner中的方法(將oracle的sql文件轉換成mysql的sql文件)呢&#xff1f; 怎么將xx.sql文件的數據庫結構導入powerdesigner 的方法呢? 現講下。 工具/原料 PowerDesigner軟件&#xff0c;oracle數據庫 方法/步驟 將要導入的庫的所有表的表結構(不要表數…

ios html圖片相對路徑,iOS 下加載本地HTML/js/css/image 等路徑問題

今天在項目中遇到一個問題&#xff1a;我將H5的文件拖入項目中&#xff0c;在webView上添加H5,運行時發現H5的樣式與圖片等都沒屏幕快照 2016-07-06 11.33.22.png有了。經過多種測試后發現&#xff1a;是路徑的問題。在ios項目下添加本地HTML/js/css/image 當拖入項目時有兩種選…

nextfloat_Java Random nextFloat()方法與示例

nextfloat隨機類nextFloat()方法 (Random Class nextFloat() method) nextFloat() method is available in java.util package. nextFloat()方法在java.util包中可用。 nextFloat() method is used to generate the next pseudo-random float value between the range 0.0 and …