php數(shù)組函數(shù)序列之a(chǎn)rray_key_exists() - 查找數(shù)組鍵名是否存在
更新時間:2011年10月29日 23:03:13 作者:
array_key_exists() 函數(shù)判斷某個數(shù)組中是否存在指定的 key,如果該 key 存在,則返回 true,否則返回 false
array_key_exists() 定義和用法
array_key_exists() 函數(shù)判斷某個數(shù)組中是否存在指定的 key,如果該 key 存在,則返回 true,否則返回 false。
語法
array_key_exists(key,array)
參數(shù) 描述
key 必需。規(guī)定鍵名。
array 必需。規(guī)定輸入的數(shù)組。
例子 1
<?php
$a=array("a"=>"Dog","b"=>"Cat");
if (array_key_exists("a",$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
輸出:
Key exists!
例子 2
<?php
$a=array("a"=>"Dog","b"=>"Cat");
if (array_key_exists("c",$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
輸出:
Key does not exist!
例子 2
<?php
$a=array("Dog",Cat");
if (array_key_exists(0,$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
輸出:
Key exists!
array_key_exists() 函數(shù)判斷某個數(shù)組中是否存在指定的 key,如果該 key 存在,則返回 true,否則返回 false。
語法
array_key_exists(key,array)
參數(shù) 描述
key 必需。規(guī)定鍵名。
array 必需。規(guī)定輸入的數(shù)組。
例子 1
復(fù)制代碼 代碼如下:
<?php
$a=array("a"=>"Dog","b"=>"Cat");
if (array_key_exists("a",$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
輸出:
Key exists!
例子 2
復(fù)制代碼 代碼如下:
<?php
$a=array("a"=>"Dog","b"=>"Cat");
if (array_key_exists("c",$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
輸出:
Key does not exist!
例子 2
復(fù)制代碼 代碼如下:
<?php
$a=array("Dog",Cat");
if (array_key_exists(0,$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
輸出:
Key exists!
您可能感興趣的文章:
- PHP中的array數(shù)組類型分析說明
- 類似php的js數(shù)組的in_array函數(shù)自定義方法
- php函數(shù)array_merge用法一例(合并同類數(shù)組)
- php專用數(shù)組排序類ArraySortUtil用法實例
- php數(shù)組(array)輸出的三種形式詳解
- php array_filter除去數(shù)組中的空字符元素
- php數(shù)組函數(shù)序列之a(chǎn)rray_keys() - 獲取數(shù)組鍵名
- php array_flip() 刪除數(shù)組重復(fù)元素
- PHP合并數(shù)組+與array_merge的區(qū)別分析
- php數(shù)組查找函數(shù)in_array()、array_search()、array_key_exists()使用實例
- php in_array() 檢查數(shù)組中是否存在某個值詳解
- PHP數(shù)組array類常見操作示例
相關(guān)文章
php中 ob_start等函數(shù)截取標準輸出的方法
這篇文章主要介紹了php中 ob_start等函數(shù)截取標準輸出的方法的相關(guān)資料,需要的朋友可以參考下2015-06-06php file_get_contents取文件中數(shù)組元素的方法
下面小編就為大家?guī)硪黄猵hp file_get_contents取文件中數(shù)組元素的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04php數(shù)組函數(shù)序列之a(chǎn)rray_combine() - 數(shù)組合并函數(shù)使用說明
array_combine() 函數(shù)通過合并兩個數(shù)組來創(chuàng)建一個新數(shù)組,其中的一個數(shù)組是鍵名,另一個數(shù)組的值為鍵值2011-10-10PHP實現(xiàn)的一致性Hash算法詳解【分布式算法】
這篇文章主要介紹了PHP實現(xiàn)的一致性Hash算法,結(jié)合實例形式詳細分析了php一致性Hash算法的概念、原理及相關(guān)實現(xiàn)與使用技巧,需要的朋友可以參考下2018-03-03