array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.apcu-exists.php', 1 => 'apcu_exists', ), 'up' => array ( 0 => 'ref.apcu.php', 1 => 'APCu 関数', ), 'prev' => array ( 0 => 'function.apcu-entry.php', 1 => 'apcu_entry', ), 'next' => array ( 0 => 'function.apcu-fetch.php', 1 => 'apcu_fetch', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/apcu/functions/apcu-exists.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PECL apcu >= 4.0.0)
apcu_exists — エントリが存在するかどうかを調べる
keys
キーを含む文字列、あるいは文字列の配列。
キーが存在する場合に true
、それ以外の場合に false
を返します。
keys
に配列を渡したときは、
存在するキーをすべて含む配列を返します。
どれも存在しない場合は空の配列を返します。
例1 apcu_exists() の例
<?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) }