Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow

StackOverflow Logo StackOverflow Logo

StackOverflow Navigation

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Add group
  • Feed
  • User Profile
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
Home/ Questions/Q 738
Next

StackOverflow Latest Questions

Saralyn
  • 0
  • 0
SaralynBegginer
Asked: April 28, 20252025-04-28T15:33:12+00:00 2025-04-28T15:33:12+00:00In: PHP

PHP APCu store then fetched associative array has key-matching problem

  • 0
  • 0
PHP APCu store then fetched associative array has key-matching problem

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.

I found a strange issue when storing then retrieving an associative array via APCu. I have a feeling it has to do with the internal serialize/deserialize routines, so I don’t know if this is a known or expected behavior. Key-matching on the fetched array is not working:

  • PHP 8.2.25 on an x86_64 running RH Enterprise Linux 9.5
  • APCu version 5.1.23 with PHP serializer
// 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 = array_flip( ["dog", "bird"] );

// get a subset array,
// by finding the keys that match in the superset array
$arDirect = array_intersect_key( $arOne, $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, $arTwo );

Results:

count($arOne)      is: 3 / JSON Text: {"cat":["meow","cat is hungry"],"dog":["woof","dog is concerned"],"bird":["chirp","bird is happy"]}

count($arOneFetch) is: 3 / JSON Text: {"cat":["meow","cat is hungry"],"dog":["woof","dog is concerned"],"bird":["chirp","bird is happy"]}

count($arDirect)   is: 2 / JSON Text: {"dog":["woof","dog is concerned"],"bird":["chirp","bird is happy"]}

count($arFetch)    is: 0 / JSON Text: []  // <-- I expected this result to be the same as $arDirect

var_dump($arOne):

array (size=3)
  'cat' => 
    array (size=2)
      0 => string 'meow' (length=4)
      1 => string 'cat is hungry' (length=13)
  'dog' => 
    array (size=2)
      0 => string 'woof' (length=4)
      1 => string 'dog is concerned' (length=16)
  'bird' => 
    array (size=2)
      0 => string 'chirp' (length=5)
      1 => string 'bird is happy' (length=13)

var_dump($arOneFetch):

array (size=3)
  'cat' => 
    array (size=2)
      0 => string 'meow' (length=4)
      1 => string 'cat is hungry' (length=13)
  'dog' => 
    array (size=2)
      0 => string 'woof' (length=4)
      1 => string 'dog is concerned' (length=16)
  'bird' => 
    array (size=2)
      0 => string 'chirp' (length=5)
      1 => string 'bird is happy' (length=13)

My workaround was to store the array as JSON encoded, then decode after fetch…but I would rather understand why this is happening.

0
  • 0 0 Answers
  • 34 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • Popular
  • Answers
  • W3spoint99

    What is Physics? Definition, History, Importance, Scope (Class 11)

    • 1 Answer
  • W3spoint99

    The Living World – Introduction, Classification, Characteristics, FAQs (Class 11 ...

    • 1 Answer
  • W3spoint99

    Explain - Biological Classification (Class 11 - Biology)

    • 1 Answer
  • Saralyn
    Saralyn added an answer When Humans look at their childhood pictures, the first thing… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Previously, length was measured using units such as the length… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Measurement forms the fundamental principle to various other branches of… January 17, 2025 at 3:25 pm

Related Questions

  • Reading fancy apostrophe PHP [duplicate]

    • 0 Answers
  • Unable to send mail via PHPMailer [SMTP->Error: Password not accepted ...

    • 0 Answers
  • Concerns when migrating from PHP 5.6 to 8.4 [closed]

    • 0 Answers
  • Laravel Auth::attempt() error: "Unknown column 'password'" when using a custom ...

    • 0 Answers
  • Core PHP cURL - header origin pass null value

    • 0 Answers

Trending Tags

biology class 11 forces how physics relates to other sciences interdisciplinary science learn mathematics math sets tutorial null sets physics physics and astronomy physics and biology physics and chemistry physics applications science science connections science education sets in mathematics set theory basics types of sets types of sets explained

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

  • About US
  • Privacy Policy
  • Questions
  • Recent Questions
  • Web Stories

© 2025 WikiQuora.Com. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.