PHP8 apcu_exists

2023-08-28 15:49 更新

(PECL apcu >= 4.0.0)

apcu_exists — 檢查條目是否存在

說明

apcu_exists(mixed $keys): mixed

檢查是否存在一個或多個 APCu 條目。

參數

keys

包含鍵的字符串或字符串數??組。

返回值

如果鍵存在則返回 true,否則返回 false 或者如果將數組傳遞給鍵,則返回包含所有現有鍵的數組,如果不存在則返回空數組。

示例

示例 #1 apcu_exists() example

<?php
$fruit = 'apple';
$veggie = 'carrot';

apcu_store('foo', $fruit);
apcu_store('bar', $veggie);

if (apcu_exists('foo')) {
echo "Foo exists: ";
echo apcu_fetch('foo');
} else {
echo "Foo does not exist";
}

echo PHP_EOL;
if (apcu_exists('baz')) {
echo "Baz exists.";
} else {
echo "Baz does not exist";
}

echo PHP_EOL;

$ret = apcu_exists(array('foo', 'donotexist', 'bar'));
var_dump($ret);

?>

以上示例的輸出類似于:

Foo exists: apple
Baz does not exist
array(2) {
  ["foo"]=>
  bool(true)
  ["bar"]=>
  bool(true)
}

參見

  • apcu_cache_info() - 從 APCu 存儲中獲取緩存信息
  • apcu_fetch() - Fetch a stored variable from the cache


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號