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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:13:04+00:00 2026-06-09T12:13:04+00:00

I have several arrays that are created in a PHP function. I want to

  • 0

I have several arrays that are created in a PHP function. I want to return all of those arrays in the return value when the function returns. However, since I can only return one array, I create an array of arrays, like so:

$return_value = array($a_config_lines, $port_values, $proto_values, $dev_values, $ca_values, $key_values, $crt_values, $key_values, $group_values, $user_values, $dh_values, $server_values, $ifconfig_pool_values, $keepalive_values, $comp_values, $verb_values, $status_values, $management_values, $a_extra_config_settings);
return $return_value;

$return_value is an array, that contains all of the other arrays, like $comp_values, $verb_values, etc.

When I return from the function, I want to immediately REVERSE what I just did. So I want to take $return_value, and split it up into the old individual arrays, but now they keys for those arrays are 0,1,2, etc… is there an easy way to do this?

Or will I have to manually set all of the keys before I return the array?

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-06-09T12:13:06+00:00Added an answer on June 9, 2026 at 12:13 pm

    If the array you return is associative, you can use extract() to pull all the component arrays back into global scope when you return it:

    // Define your array as an associative array, keys named the same as the component variables
    return = array(
      'a_config_lines' => $a_config_lines, 
      'port_values' => $port_values, 
      'proto_values' => $proto_values, 
      // etc...
    );
    

    Upon calling your function:

    // extract() the returned array, to dump all the vars back into global scope
    $return = your_function();
    extract($return);
    // All arrays are now at global scope
    var_dump($port_values);
    var_dump($a_config_lines);
    

    However, there’s little value to extracting them back into global scope, when you can just access them tidily from the array. This saves you from polluting the global scope with a bunch of new variables.

    // Better! Just use the array.
    $return = your_function();
    var_dump($return['port_values']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following php function, that creates an array of all the days between
I am using jQuery 1.7.1 (but that's probably irrelevant). I have several JavaScript arrays
I have the following checkbox created by a loop: <input type='checkbox' value=0 name='<?php echo
I have a mutable array that is retained and storing several objects. At some
I have several 450 element character arrays (storing bitmap data to display on lcd
I have a struct which has several arrays within it. The arrays have type
I have an object whose value may be one of several array types like
I have several xml files with different node structure. I want to extract xml
I have several HTML elements (buttons) that fire the same JQuery AJAX request. When
I have several Delphi programs that maintain connections to a database (some Oracle, some

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.