Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP APC更新键和值数组_Php_Arrays_Apc - Fatal编程技术网

PHP APC更新键和值数组

PHP APC更新键和值数组,php,arrays,apc,Php,Arrays,Apc,我有以下测试代码 现在它是一个非常小的数组,但在实时非常大 如何仅更新APC FOO中键1 direct的值 $test = array( array( 'name' => 'Mike', 'lastname' => 'Last', ), array( 'name' => 'test', 'lastname' => 'testlast', ), array(

我有以下测试代码

现在它是一个非常小的数组,但在实时非常大

如何仅更新APC FOO中键1 direct的值

$test = array(
    array(
        'name' => 'Mike',
        'lastname' => 'Last',
    ),
    array(
        'name' => 'test',
        'lastname' => 'testlast',
    ),
    array(
        'name' => 'anothertest',
        'lastname' => 'anothertestlast',
    ),
);
apc_store('foo', $test);
print_r(apc_fetch('foo'));

我认为不能直接在缓存中修改变量。我最好的猜测是编写一个函数,从缓存中获取数据,对其进行修改,然后将其存储回缓存中。可能是这样的:

function apc_update_array($cacheKey, $arrayKey, $array)
{
    $data = apc_fetch($cacheKey);
    $data[$arrayKey] = $array;
    apc_store($cacheKey, $data);
}
使用该函数,您只需运行以下代码即可完成

apc_update_array(
    'foo',
    1,
    array(
        'name' => 'differenttest',
        'lastname' => 'differenttestlast',
    )
);