W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
(PECL apcu >= 4.0.0)
apcu_cas — 用新值更新舊值
apcu_cas(string $key, int $old, int $new): bool
apcu_cas() 如果舊參數(shù)與當(dāng)前存儲的值與新參數(shù)的值匹配,則更新已存在的整數(shù)值。
key
正在更新的值的key。
old
舊值(當(dāng)前存儲的值)。
new
要更新到的新值。
成功時返回 true, 或者在失敗時返回 false。
示例 #1 apcu_cas() example
<?php
apcu_store('foobar', 2);
echo '$foobar = 2', PHP_EOL;
echo '$foobar == 1 ? 2 : 1 = ', (apcu_cas('foobar', 1, 2) ? 'ok' : 'fail'), PHP_EOL;
echo '$foobar == 2 ? 1 : 2 = ', (apcu_cas('foobar', 2, 1) ? 'ok' : 'fail'), PHP_EOL;
echo '$foobar = ', apcu_fetch('foobar'), PHP_EOL;
echo '$f__bar == 1 ? 2 : 1 = ', (apcu_cas('f__bar', 1, 2) ? 'ok' : 'fail'), PHP_EOL;
apcu_store('perfection', 'xyz');
echo '$perfection == 2 ? 1 : 2 = ', (apcu_cas('perfection', 2, 1) ? 'ok' : 'epic fail'), PHP_EOL;
echo '$foobar = ', apcu_fetch('foobar'), PHP_EOL;
?>
以上示例的輸出類似于:
$foobar = 2
$foobar == 1 ? 2 : 1 = fail
$foobar == 2 ? 1 : 2 = ok
$foobar = 1
$f__bar == 1 ? 2 : 1 = fail
$perfection == 2 ? 1 : 2 = epic fail
$foobar = 1
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: