Content · Programming · PHP

PHP apcu_exists() Function: Usage and Examples

Learn how PHP apcu_exists works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Checks whether APCu holds one or several keys.

What Is apcu_exists() in PHP?

Checks whether APCu holds one or several keys.

Its syntax is:

apcu_exists(string|array $keys): bool|array

Parameters:

  • $keys — Accepted as string|array; required argument.

Return type: bool|array. For multiple keys the result is an array of keys that exist. A missing item and an item storing false are different cases.

Availability: Requires APCu enabled for the current PHP SAPI.

Example 1: Basic Usage

<?php

apcu_store("active", true);
var_dump(apcu_exists("active"));

Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. For multiple keys the result is an array of keys that exist. A missing item and an item storing false are different cases.

Example 2: A Different Input

<?php

apcu_store("alpha", 1);
print_r(apcu_exists(["alpha", "missing"]));

Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. For multiple keys the result is an array of keys that exist. A missing item and an item storing false are different cases.

Practical Example: Applying It in a Program

<?php

$keys = ["frontpage", "navigation"];
$present = apcu_exists($keys);
foreach ($keys as $key) { echo $key . ": " . (in_array($key, $present, true) ? "yes" : "no") . PHP_EOL; }

Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. For multiple keys the result is an array of keys that exist. A missing item and an item storing false are different cases.

Important Behavior and Edge Cases

  • Key behavior: For multiple keys the result is an array of keys that exist. A missing item and an item storing false are different cases.
  • Environment: Requires APCu enabled for the current PHP SAPI.

Comparison With Related Functions

FunctionPurpose
apcu_exists()checks whether APCu holds one or several keys.
apcu_fetch()apcu_exists() checks key presence without retrieving a value; apcu_fetch() obtains the cached value.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: For multiple keys the result is an array of keys that existFor multiple keys the result is an array of keys that exist. A missing item and an item storing false are different cases.

Key Takeaways

  • checks whether APCu holds one or several keys.
  • For multiple keys the result is an array of keys that exist. A missing item and an item storing false are different cases.
  • Requires APCu enabled for the current PHP SAPI.

Summary: For multiple keys the result is an array of keys that exist. A missing item and an item storing false are different cases.

Share this resourceSend this page to someone who may find it useful.