apcu_cas

(PECL apcu >= 4.0.0)

apcu_casUpdates an old value with a new value

说明

apcu_cas ( string $key , int $old , int $new ) : bool

apcu_cas() updates an already existing integer value if the old parameter matches the currently stored value with the value of the new parameter.

参数

key

The key of the value being updated.

old

The old value (the value currently stored).

new

The new value to update to.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

Example #1 apcu_cas() example

<?php
apcu_store
('foobar'2);
echo 
'$foobar = 2'PHP_EOL;
echo 
'$foobar == 1 ? 2 : 1 = ', (apcu_cas('foobar'12) ? 'ok' 'fail'), PHP_EOL;
echo 
'$foobar == 2 ? 1 : 2 = ', (apcu_cas('foobar'21) ? 'ok' 'fail'), PHP_EOL;

echo 
'$foobar = 'apcu_fetch('foobar'), PHP_EOL;

echo 
'$f__bar == 1 ? 2 : 1 = ', (apcu_cas('f__bar'12) ? 'ok' 'fail'), PHP_EOL;

apcu_store('perfection''xyz');
echo 
'$perfection == 2 ? 1 : 2 = ', (apcu_cas('perfection'21) ? '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

参见

相关文章
php apcu 函数 cache a new variable in the data storephp apcu 函数 updates an old value with a new valuephp cubrid mysql 兼容性函数 return the numerical value of the error message from previous cubrid operationphp ibm db2 函数 retrieves an option value for a statement resource or a connection resourcephp db++ 函数 create a new secondary index for a relationphp firebird/interbase 函数 increments the named generator and returns its new valuephp informix 函数 updates the content of the char objectphp imap 函数 rename an old mailbox to new mailboxphp uopz 函数 sets value of existing class or instance propertyphp com 函数 assigns a new value for a variant objectphp vpopmail 函数 add a new virtual domainphp wincache 函数 compares the variable with old value and assigns new value to itphp quickhashinthash this method updates an entry in the hash with a new value or adds a new one if the entry doesn t existphp quickhashinthash this method updates an entry in the hash with a new valuephp quickhashintstringhash this method updates an entry in the hash with a new value or adds a new one if the entry doesn t existphp quickhashintstringhash this method updates an entry in the hash with a new valuephp quickhashstringinthash this method updates an entry in the hash with a new value or adds a new one if the entry doesn t existphp quickhashstringinthash this method updates an entry in the hash with a new valuephp sdo 函数 get the old value for the changed propertyphp weakmap updates the map with a new key value pair
关注编程学问公众号