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

  • Home
  • SEARCH
  • 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 7887665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:38:22+00:00 2026-06-03T05:38:22+00:00

In PHP I need to pass some arguments to a function by reference .

  • 0

In PHP I need to pass some arguments to a function by reference.
I don’t want to write 2 different methods for similar behaviour.
So i need to select behaviour by argument.
But I can’t pass null by reference.
So I created a dummy array.

So i run it either by

    $temp[0]=-1;
    $this->doSomething($bigIds, $temp);
or
    $temp[0]=-1;
    $this->doSomething($temp, $smallIds);


public function doSomething(&$bigIds, &$smallIds) {
        if ($bigIds[0] != -1) {
             // make some thing
        }
        if ($smallIds[0] != -1) {
             // make some thing
        }
}

Is there a better/ elegant way to do this?

  • 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-03T05:38:23+00:00Added an answer on June 3, 2026 at 5:38 am

    I would suggest an enum but this is PHP. So this should do it for you:

    class YourClass
    {
        const DoSomethingSmall = 0;
        const DoSomethingBig = 1;
    
        public function doSomething(&$ids, $actionType) {
            // can also use a switch here
            if($actionType == self::DoSomethingSmall) {
                // do small
            }
            else if($actionType == self::DoSomethingBig) {
                // do big
            }
        }
    }
    

    Then you can do:

    $this->doSomething($bigIds, self::DoSomethingBig);
    $this->doSomething($smallIds, self::DoSomethingSmall);
    

    From outside the class you can use YourClass::DoSomethingBig and YourClass::DoSomethingSmall

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

Sidebar

Related Questions

This question is regarding getopt function in php. I need to pass two parameter
The regular expression ^/wp-[^./]+\.php$ matches: wp-config.php wp-commentsrss2.php wp-pass.php wp-rdf.php [...] But I need another
I'm using php and need to do a bunch of select statements on the
I want to send messages to mobile phones using wamp server in php.I need
I have to pass some strings from a java servlet to a php script.
I am trying to upload a file using php,and i need to pass a
I want to return the PHP token_get_all() function as JSON. I also want token_get_all
class MyClass { private function isExist($arr) { // need to do some formatting here
In my php code I need to invoke a script and passing it some
I have several situations where I need to pass multi-dimensional PHP arrays into Javascript/jQuery.

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.