Я нашел странную проблему при хранении, а затем в поиске ассоциативного массива через APCU. У меня такое ощущение, что это связано с рутиной внутренней сериализации/десериализации, поэтому я не знаю, является ли это известным или ожидаемым поведением. Key-matching on the fetched array is not working:
PHP 8.2.25 on an x86_64 running RH Enterprise Linux 9.5
// build superset array
$arOne = ["cat"=>["meow", "cat is hungry"],"dog"=>["woof", "dog is concerned"],"bird"=>["chirp", "bird is happy"]];
//specify subset keys to look for
$arTwo = ["dog", "bird"];
// get a subset array, by finding the keys that match in the superset array
$arDirect = array_intersect_key( $arOne, array_flip( $arTwo ) );
// store our superset array into APCU
apcu_store("animals",$arOne,60000);
// get a copy of our superset array, from APCU
$arOneFetch = apcu_fetch("animals");
// get a second subset array, by finding the keys that match in the copy of our superset array
$arFetch = array_intersect_key( $arOneFetch, array_flip( $arTwo ) );
< /code>
Результаты: < /p>
count($arOne) is: 3 with json_encode: {"cat":["meow","cat is hungry"],"dog":["woof","dog is concerned"],"bird":["chirp","bird is happy"]}
count($arOneFetch) is: 3 with json_encode: {"cat":["meow","cat is hungry"],"dog":["woof","dog is concerned"],"bird":["chirp","bird is happy"]}
count($arDirect) is: 2 with json_encode: {"dog":["woof","dog is concerned"],"bird":["chirp","bird is happy"]}
count($arFetch) is: 0 with json_encode: [] //
Подробнее здесь: [url]https://stackoverflow.com/questions/79588921/php-apcu-store-then-fetched-associative-array-has-key-matching-problem[/url]
Я нашел странную проблему при хранении, а затем в поиске ассоциативного массива через APCU. У меня такое ощущение, что это связано с рутиной внутренней сериализации/десериализации, поэтому я не знаю, является ли это известным или ожидаемым поведением. Key-matching on the fetched array is not working: [list] [*]PHP 8.2.25 on an x86_64 running RH Enterprise Linux 9.5 [*]APCu version 5.1.23 with default (PHP) serializer [/list]
[code]// build superset array $arOne = ["cat"=>["meow", "cat is hungry"],"dog"=>["woof", "dog is concerned"],"bird"=>["chirp", "bird is happy"]];
//specify subset keys to look for $arTwo = ["dog", "bird"];
// get a subset array, by finding the keys that match in the superset array $arDirect = array_intersect_key( $arOne, array_flip( $arTwo ) );
// store our superset array into APCU apcu_store("animals",$arOne,60000);
// get a copy of our superset array, from APCU $arOneFetch = apcu_fetch("animals");
// get a second subset array, by finding the keys that match in the copy of our superset array $arFetch = array_intersect_key( $arOneFetch, array_flip( $arTwo ) ); < /code> Результаты: < /p> count($arOne) is: 3 with json_encode: {"cat":["meow","cat is hungry"],"dog":["woof","dog is concerned"],"bird":["chirp","bird is happy"]}
count($arOneFetch) is: 3 with json_encode: {"cat":["meow","cat is hungry"],"dog":["woof","dog is concerned"],"bird":["chirp","bird is happy"]}
count($arDirect) is: 2 with json_encode: {"dog":["woof","dog is concerned"],"bird":["chirp","bird is happy"]}