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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:31:54+00:00 2026-06-07T01:31:54+00:00

I have an array $params with the following content: Array( 0 => array 1

  • 0

I have an array $params with the following content:

Array(
  0 => "array"
  1 => "arrayName" //variable
  2 => "key1" //optional&variable ie. 0 or 'foo'
  3 => "key2" //optional&variable ie. 0 or 'foo'
  //etc.
)

Also, I have an stdObject that contains all my variables for the page that is being requested (MVC style).
So, I could have an array in there like this:

$std = new stdObject();
$std->arrayName->array('foo', 'bar');

Now I want the first value of the $std array. So I am using the “key1” parameter in $params and set this to ‘0’ so it will pick the $std->arrayName[0] value (‘foo’). Note that I am not using the “key2” parameter since I don’t want to select $std->arrayName[key1][key2].

But what if I need the value of a nested array?

$std = new stdObject();
$std->arrayName->array('foo', array('bar', 'fish'));

I will request the $std->arrayName[1][1] value (‘fish’) by setting the “key1” parameter to 1 and the “key2” parameter to 1 as well. So it will select $std->arrayName[key1][key2].

But what if I have 10 arrays nested in each other? highly unlikely, but it’s possible. I want to select $std->arrayName[key1][key2][key3][..][key10] to select a certain value that’s located there.
For example: $std->arrayName[0][3][4][6][2][9][‘foo’][‘bar][9][2];

So my question is: how do I select the value of a certain array (arrayName) by the values defined in another array ($params) that act as the keys for the first array (arrayName). But, the amount of keys (values in $params) is optional.

Maybe the question isn’t completely understandable, so feel free to ask more information.

  • 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-07T01:31:56+00:00Added an answer on June 7, 2026 at 1:31 am

    You need to loop the key array and assign each level to a variable, until you reach the end when you should have the value you want.

    Something like this (untested, no error checking):

    function array_value_at ($array, $keys) {
      foreach ($keys as $key) {
        $array = $array[$key];
      }
      return $array;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following piece of code, where params[:sort] is a variable whose value
When I have array of objects, when I type the name of variable in
I have the following method signature: public static void InvokeInFuture(Delegate method, params object[] args)
I have this array: --- !map:ActiveSupport::HashWithIndifferentAccess search: !map:ActiveSupport::HashWithIndifferentAccess address: test I apply the following
I have the following code: $routes = array( 'twitter_output' => new Zend_Controller_Router_Route( 'twitter/:username\.:format', array('controller'
I use select queries as by following code: $params = array( 'username' => 'root',
I've got the following routes.php configuration Router::connect('/:type/:slug;:id', array( 'controller' => 'content', 'action' => 'show',
I have the following where I'm trying to send list/array to MVC controller method:
I have array INPUTFILES with n files INPUTFILES=( file_0 ... files_n-1 ) And i
I have array of hashes: @array = [{:id => 1, :status=>R}, {:id => 1,

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.