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 7592013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:47:57+00:00 2026-05-30T20:47:57+00:00

I have got a couple of functions that manipulate data in an array, for

  • 0

I have got a couple of functions that manipulate data in an array, for example unset_data() you pass it the value and an unlimited amount of string args like:

unset_data( $my_array, "firstname", "password" );

and it can handle multi-dimentional arrays etc, quite simple.

But should this function use a reference to the array and change it directly?

Or should i return the new array with the values unset.

I can never decide whether a function should use reference or not,

Is there like, specific cases or examples when and when to not use them??

Thanks

  • 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-05-30T20:47:58+00:00Added an answer on May 30, 2026 at 8:47 pm

    I’d ask myself what the expected use case of the function is. Does the typical use case involve keeping the original data intact and deriving new data from it, or is the explicit use case of this function to modify data in place?

    Say md5 would modify data in place, that would be pretty inconvenient, since I usually want to keep the original data intact. So I’d always have to do this:

    $hash = $data;
    md5($hash);
    

    instead of:

    $hash = md5($data);
    

    That’s pretty ugly code, forced on you by the API of the function.

    For unset though, I don’t think the typical use case is for deriving new data:

    $arr = unset($arr['foo']);
    

    That seems pretty clunky as well as possibly a performance hit.

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

Sidebar

Related Questions

I got a couple of JNI functions that have to work on the same
I have a couple of functions that perform HTTP POST/GET/HEAD requests. For the POST
I have created a couple of simple functions in VB.NET that simply return a
I've got a couple of colleagues who love Access and have lots of important
I've possible got to implement SAML for a couple of sites we have and
I have a PHP array that I'd like to duplicate but only copy elements
I have got a couple of tables with a parent child relationship. I want
I have a function that executes to slide open a couple divs to reveal
I've got some data in JSON format that I want to do some visualization
I have a function that takes a couple of font parameters, and produces the

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.