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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:14:37+00:00 2026-06-02T04:14:37+00:00

I have two variables, which are both arrays: $var1=array(); $var1[‘something’][‘secondary_something’][1]=foo; $var1[‘something’][‘secondary_something’][2]=foo; $var1[‘something’][‘secondary_something’][3]=foo; $var1[‘something’][‘secondary_something’][4]=foo; Now

  • 0

I have two variables, which are both arrays:

$var1=array();

$var1['something']['secondary_something'][1]="foo";
$var1['something']['secondary_something'][2]="foo";
$var1['something']['secondary_something'][3]="foo";
$var1['something']['secondary_something'][4]="foo";

Now I have a function, that takes an array for input:

function something($input=array()){

print_r($input);//print the array out

}//end of function

But I need $input to be like a reference to $var1, so when I call the function, appending to variable 2 ($input) like this:

$myInputVar=array();
$myInputVar['something']['secondary_something'][]="foo";
$myInputVar['something']['secondary_something'][]="foo";
//Notice how I append to the var above, not giving a key name in the third dimension of the array.
something($myInputVar);

Now that would simply print:

Array ( [something] => Array ( [secondary_something] => Array ( [0] => foo [1] => foo ) ) )

But I need the second var ($input, from the function) to be a reference of the first var ($var1).

So, the end result should be:

Array ( [something] => Array ( [secondary_something] => Array ( [5] => foo [6] => foo ) ) )

Some guys have told me to use the =& (which makes one var a reference to another), but I just can’t seem to get my head around how I would do it with =& in this case.

Is what I’m trying to do even possible? If so, could you please shine some light on it.

  • 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-02T04:14:39+00:00Added an answer on June 2, 2026 at 4:14 am

    I am struggling to understand what you are trying to achieve.
    Why would you print the array out?
    You always need a value and an array if you want to push something into the array.
    You can do this with

    function something(&$array, $val) { // take the assigned $array as reference
      $array[] = $val;
    }
    

    Then calling with

    $test = array();
    something($test, 'foo');
    print_r($test); // => array ( 'test' )
    

    I hope this helps


    EDIT

    function something(&$array, $array_new) {
       $array = array_merge($array, $array_new); // to combine/merge both arrays
       // please keep in mind that $array is technically $var, because it references to this variable
    }
    
    $var1=array();
    
    $var1['something']['secondary_something'][1]="foo";
    $var1['something']['secondary_something'][2]="foo";
    $var1['something']['secondary_something'][3]="foo";
    $var1['something']['secondary_something'][4]="foo";
    
    $myInputVar=array();
    $myInputVar['something']['secondary_something'][]="foo";
    $myInputVar['something']['secondary_something'][]="foo";
    
    something($var, $myInputVar);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two string variables which are both file paths. The code that worked
I have two Python functions, both of which take variable arguments in their function
I have a function in view.py which returns two variables i.e. a dictionary named
I have an irregular mesh which is described by two variables - a faces
I have two variables. weekStartDate and startDate. they both hold essentially the same timestamp:
I've got a common situation where you have two variables (xSpeed and ySpeed) which
I have two properties NSString, both of which I have synthesized and are readonly
I have two variables readARP and readFPING which will have a series of IP's
I have two variables, key and value , and I want to add them
I have two variables: char charTime[] = TIME; char buf[] = SOMETHINGELSE; I want

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.