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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:45:37+00:00 2026-05-20T03:45:37+00:00

I use multidimensional arrays to store product attributes (well Virtuemart does, to be precise).

  • 0

I use multidimensional arrays to store product attributes (well Virtuemart does, to be precise).
When I tried to echo the sub-arrays value, if the sub-array did not exist PHP threw:

Fatal error: Cannot use string offset
as an array

To get around this, I attempted to create a function to check on every array level if it is an actual array, and if it is empty (when trying on the whole thing at once such as: is_array($array['level1']['level2']['level3']), I got the same error if level1 or level2 are not actual arrays).

This is the function ($array contains the array to check, $array_levels is an array containing the names of the sub-arrays, in the order they should apper):

function check_md_array($array,$array_levels){
    if(is_array($array)){
        $dimension = null;  //This will store the dimensions string

        foreach($array_levels as $level){
            $dimension .= "['" . $level . "']"; //Add the current dimension to the dimensions string

            if(!is_array($array/* THE CONTENT OF $dimension SHOULD BE INSERTED HERE*/)){
                return false;
            }
        }           
        return true;
    }
}

How can I take the string contained in $dimensions, and insert it into the code, to be part of the statement?

  • 1 1 Answer
  • 5 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-20T03:45:38+00:00Added an answer on May 20, 2026 at 3:45 am

    Short of doing an eval, I don’t think you can do it.

    if(eval("!is_array($array".$dimension.")"))
        return false
    

    However, this is another way to do it

    function check_md_array($array,$array_levels){
        if(!is_array($array))
             return false;
    
        foreach($array_levels as $level){
            if(!isset($array[$level]) || !is_array($array[$level]))
                return false;
            $array = $array[$level];
        }
    
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multidimensional array or arrays which I also use in my configuration
I have been developing some code that uses Data.Array to use multidimensional arrays, now
I have very long multidimensional array that have many sub arrays. I would like
When I was using C++ in college, I was told to use multidimensional arrays
I am using a multidimensional array and I am trying to use php to
I have two questions regarding the multidimensional arrays. I declared a 3D array using
I have just noticed that a multidimensional array in C# does not implement IEnumerable<T>
I was wondering how to use array_push to multidimensional arrays? I have a multidimensional
I basically want to use str_replace() all values of a multidimensional array. I can't
Im looking for an example of multidimensional arrays. I have an array of thumbtails

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.