Content · Programming · PHP

PHP apcu_delete() Function: Usage and Examples

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

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

Removes one or more entries from the APCu cache.

What Is apcu_delete() in PHP?

Removes one or more entries from the APCu cache.

Its syntax is:

apcu_delete(string|array|APCUIterator $key): mixed

Parameters:

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

Return type: mixed. Deleting a missing single key returns false. Deleting an array can return a list of failed keys.

Availability: Requires APCu enabled for the current PHP SAPI.

Example 1: Basic Usage

<?php

apcu_store("temporary", "value");
var_dump(apcu_delete("temporary"));

Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. Deleting a missing single key returns false. Deleting an array can return a list of failed keys.

Example 2: A Different Input

<?php

apcu_store("one", 1);
apcu_store("two", 2);
print_r(apcu_delete(["one", "two"]));

Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. Deleting a missing single key returns false. Deleting an array can return a list of failed keys.

Practical Example: Applying It in a Program

<?php

$cacheKey = "report:latest";
if (apcu_exists($cacheKey)) { apcu_delete($cacheKey); echo "Cache invalidated"; }

Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. Deleting a missing single key returns false. Deleting an array can return a list of failed keys.

Important Behavior and Edge Cases

  • Key behavior: Deleting a missing single key returns false. Deleting an array can return a list of failed keys.
  • Environment: Requires APCu enabled for the current PHP SAPI.

Comparison With Related Functions

FunctionPurpose
apcu_delete()removes one or more entries from the APCu cache.
apcu_clear_cache()apcu_clear_cache() removes all user cache entries; apcu_delete() removes selected keys only.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: Deleting a missing single key returns falseDeleting a missing single key returns false. Deleting an array can return a list of failed keys.

Key Takeaways

  • removes one or more entries from the APCu cache.
  • Deleting a missing single key returns false. Deleting an array can return a list of failed keys.
  • Requires APCu enabled for the current PHP SAPI.

Summary: Deleting a missing single key returns false. Deleting an array can return a list of failed keys.

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