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

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9136369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:56:37+00:00 2026-06-17T08:56:37+00:00

I came across some PHP behavior that I think is subtle, but pretty cool.

  • 0

I came across some PHP behavior that I think is subtle, but pretty cool. But I don’t understand how…

$test=array('a'=>'c', 'b'=>'c');
unset($test['a']);
var_dump($test);

This prints

array(1) { ["b"]=> string(1) "c" }

I would have expected the array to be emptied out. After all, $test[‘a’] evaluates to ‘c’ so the unset function only sees ‘c’ but knows it was just the first ‘c’ value I wanted removing?

My guess is the interpeter is super smart and looks inside the array inside the parameter given to it – but that’s purely conjecture …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:56:37+00:00Added an answer on June 17, 2026 at 8:56 am

    Erm, no. unset is not a function, it is a language construct. Therefore it doesn’t necessarily follow the same rules.

    In this case, however, it actually works similarly to a pass-by-reference. It takes the reference to the variable, and destroys it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Came across some code today that had a javascript array, made in php, using
I recently came across some code that looks something like this: <head> <?php /*
I came across some PHP code that was written by a co-worker (it was
I've been developing with PHP for some years now, and recently came across this
I came across some javascript at work today that used jQuery to fetch two
I came across some legacy code that contains a function like this: LPCTSTR returnString()
I came across some strange behavior of asp:PlaceHolder , it removes whitespaces between the
I heard this term many times when I came across some protocol implementations, but
I'm reviewing a .NET project, and I came across some pretty heavy usage of
I came across some code recently that used a custom error handler to turn

Explore

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

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

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.