PHP8 apcu_dec

2023-08-28 15:38 更新

(PECL apcu >= 4.0.0)

apcu_dec — 減少存儲(chǔ)的數(shù)量

說明

apcu_dec(
    string $key,
    int $step = 1,
    bool &$success = ?,
    int $ttl = 0
): int|false

減少存儲(chǔ)的整數(shù)值。

參數(shù)

key

值減少的key。

step

要減少的步驟或值。

success

可以選擇將成功或失敗布爾值傳遞給此引用的變量。

ttl

如果操作插入新值(而不是遞減現(xiàn)有值),則使用 TTL。

返回值

成功時(shí)返回鍵值的當(dāng)前值,或者在失敗時(shí)返回 false

示例

示例 #1 apcu_dec() example

<?php
echo "Let's do something with success", PHP_EOL;

apcu_store('anumber', 42);

echo apcu_fetch('anumber'), PHP_EOL;

echo apcu_dec('anumber'), PHP_EOL;
echo apcu_dec('anumber', 10), PHP_EOL;
echo apcu_dec('anumber', 10, $success), PHP_EOL;

var_dump($success);

echo "Now, let's fail", PHP_EOL, PHP_EOL;

apcu_store('astring', 'foo');

$ret = apcu_dec('astring', 1, $fail);

var_dump($ret);
var_dump($fail);
?>

以上示例的輸出類似于:

Let's do something with success
42
41
31
21
bool(true)
Now, let's fail

bool(false)
bool(false)

參見

  • apcu_inc() - Increase a stored number


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)