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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:26:30+00:00 2026-05-24T01:26:30+00:00

I used a modified version of the code here Determining what classes are defined

  • 0

I used a modified version of the code here Determining what classes are defined in a PHP class file to create a multidimensional array of classes and functions from a specific list of files. What I ended up with is this (I know the names are messed up but I was goofing off and would have to go back and change class names and functions names in 3 different files so lets assume these were legitimate class names and function names),

Array
(
    [0] => Array
        (
            [namethis_whatever_I_want] => Array
                (
                    [0] => another_function
                    [1] => whatever_function
                )

        )

    [1] => Array
        (
            [tc_class_simplevar] => Array
                (
                    [0] => set_var_test
                    [1] => get_var_test
                )

        )

    [2] => Array
        (
            [another_freekin_class] => Array
                (
                    [0] => some_function
                    [1] => another_crazy_function
                )

        )

)

So now I need to be able to access the class names and the function names under each class without knowing what the index is for any of them. I’ve tried for loops, foreach, and using counters like $i and $ii to access them by there numerical index but nothing I try will print out anything but garbage or errors.

I was thinking something like embedded foreach statements

$i = 0; 
foreach($array as $class){
  echo $class[$i];
  $ii = 0; 
  foreach($class as $val){
  echo $val[$ii];
  $ii++;
  }
$i++;
}

But no luck with that.

Also trying to access $array[$i][$i]; or $array[$i][$ii]; throws an error bad offset 0

I’m sure there will be an issue with the class array index actually being named the class name but I was thinking I could still use the numerical index for that.

Basically I am totally confused about how to access the data and could use a point in the right direction.

I will need to be able to get a class name and then get all of the function names that are under that class and will need to be able to access them at different points throughout my program by retrieving them from the array.

Thank you

I hate answering my own question just minutes after asking others for help. I feel as though I wasted your time.

You guys are right about the foreach but this was a tricky one. Asking the question was kinda helpful in talking myself through what I needed to find so it dawned on me where the problem was.

There are 3 layers to this array. There’s an array containing 3 arrays and each of them has a string instead of numerical for it’s index. Each of them containing there own elements.

So I had to iterate through arrays 1,2,3 getting the string index’s of each of their elements and then use that string element along with numerical elements to get the inner elements of the inner most arrays. Ok that confused me but here’s the code that worked for me, using echo’s and some slight formatting so I could see it working.

$size = sizeof($objectList);
for($i = 0; $i < $size; $i++){
    foreach($objectList[$i] as $key => $val){
        $className = $key;
        echo $className . ": <br/>";
        foreach($objectList[$i][$className] as $val){
            $functionName = $val;
            echo $functionName . " , ";
        }
    echo "<br/><br/>";
    }
}

Resulted in

namethis_whatever_I_want:
another_function , whatever_function ,

tc_class_simplevar:
set_var_test , get_var_test ,

another_freekin_class:
some_function , another_crazy_function ,

For anyone else in case it helps, here’s Marks version with my arrays and variable names to compare. I’d say this way is the cleanest and it cuts out a couple lines of code.

foreach($objectList as $objects){
    foreach($objects as $classname => $functions){
        $cn = $classname;
        foreach($functions as $functionname){
            $fn = $functionname;
        }
    }
}

Thank you for your help 🙂

  • 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-24T01:26:31+00:00Added an answer on May 24, 2026 at 1:26 am

    foreach also allows you to specify a key portion of the iterator, so you can loop through associative arrays as:

    foreach($array as $key => $val){
        echo $array[$key]; // prints $val
    }
    

    So, in your case:

    foreach($rootarray as $classarray){
        foreach($classarray as $classname => $functions){
            // $classname contains the name of the class
            foreach($functions as $functionname){
                // $functionname contains the name of the function
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a model POCO class called Recipe ; a corresponding RecipeRepository persists
I'm using the latest wordpress version, I installed it on another machine in my
I will use the URLRequest to upload the modified image in Flex. It works
I'd like to use a variable like $GET[name] that always outputs a MySQL-safe version
I am implementing a haskell program which compares each line of a file with
Android is 32-bit ARM. wiki Description: 1) So, 32/64 or 8/12/16 Bit compiler is
I have problems with a specific query when using the sqlite3_step function: SELECT DISTINCT
I have two apps in the app store, both through MonoTouch but after upgrading
Following on from one of my previous questions to do with method design I
I'm implementing a content database for a C# Asp.Net MVC3 website in Sql Server.

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.