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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:39:04+00:00 2026-05-24T03:39:04+00:00

long time reader, first time question-er. I’ve found myself in a unique situation, and

  • 0

long time reader, first time question-er.

I’ve found myself in a unique situation, and the most effective way I can find to solve my problem is by building a string of keys to obtain a value. I was having trouble with the code block indenting on here, so I’ve provided my code snippet on Pastebin: http://pastebin.com/Nn8xS5Vx

What I’m trying to do there is step through each level of the structure, checking each level for errors, and if any are found, reporting them back into the $errors_array in the following format:

[Level eg:Enterprise]
  [0] Enterprise Name
[Platform]
  [0] Platform Name

The problem is that I’m not going down through the levels when I retrieve the name, it’s looking at the root of the array. My idea was to write a for loop to construct a string to provide the current level, so the name can be retrieved.

What I’m looking to do is build a string containing keys of each level, and then use that string of keys to refer to the $node variable and pull the name respectively. Here’s a pseudo-example:

$keyString = "[Enterprise][Platform][Offering]"

And I would then use something to the effect of:

$node[$keystring]['name']

I hope I’ve explained that well enough. If anyone has any suggestions as to how I could achieve this, or even a better method of getting the same end result, I would greatly appreciate 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-05-24T03:39:04+00:00Added an answer on May 24, 2026 at 3:39 am

    If I’ve understood your problem correctly, you want to get a value in a nested array by a list of keys. There are a few ways to achieve this. Here’s a couple:

    // setup
    $data = array(
        'foo' => array(
            'bar' => array(
                'baz' => array(
                    'quux' => 'value'
                )
            )
        )
    );
    
    $search = array('foo', 'bar', 'baz', 'quux');
    
    // Method 1 - search by reference:
    $value = $data;
    
    foreach ($search as $key) {
        if (is_array($value) && array_key_exists($key, $value)) {
            $value = &$value[$key]; // use the reference to chase down the array
        } else {
            // handle errors here
        }
    }
    
    var_dump($value); // 'value'
    
    
    // Method 2 - search by recursion:
    function getValue($value, array $keys) {
        if ($keys === array()) {
            return $value; // got to the end of the list of keys
        }
    
        $key = array_shift($keys);
    
        if (is_array($value) && array_key_exists($key, $value)) {
            return getValue($value[$key], $keys);
        }
    
        // handle errors here
    }
    
    var_dump(getValue($data, $search)); // 'value'
    

    I think this slightly simplifies your problem, but I hope it helps.

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

Sidebar

Related Questions

First time poster, long time reader. I searched and found no questions that answered
Long time reader, first time poster. Any help is greatly appreciated. I have crafted
(Long time reader of SO, first time asking a q. I'm quite new to
first time poster, long time reader so be gentle with me :) See the
Long time reader, first time poster. Working on a web site at http://www.howardpitch.com/ ,
long time reader, first time poster. I’m coming with an issue that many of
Long time reader, first time poster. I'm a big noob when it comes to
First time poster, long time reader. I've been having a problem with figuring this
Long time reader, first time poster asks: After many weeks of google and forum
Long time reader, first time poster. One day I hope to be answering questions

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.