• 0

PHP: four-dimensional array question


Question

I'm working with my first four-dimensional array in any programming language. (Basically, it's a table inside each cell of another table.)

Is there any way to methodically load all the values into the array without using four nested loops? That's what I currently have, and it does work, but I'm a little bit afraid to use it, since it seems like it could take a while if it gets hung up.

EDIT: Also, is there a way in PHP to detect the size of a multidimensional array?

Thanks in advance!

Edited by A4B4
Link to comment
https://www.neowin.net/forum/topic/568134-php-four-dimensional-array-question/
Share on other sites

2 answers to this question

Recommended Posts

  • 0

If your using a 4 dimensional array for anything other than learning arrays for a class or something, you are most likely attempting to accomplish your task the wrong way.

So I want to ask, what are you trying to do? You may be better off creating objects to represent your 4D array. It will save you some debug time and hassle down the road.

  • 0

Ahh! I didn't realize PHP had OOP support. I'll look into that--perhaps it's time to upgrade books. Thanks!

What I'm doing is showing detailed statistics on a survey. I have several dozen groups (1st dimension), each answering several dozen questions (2nd dimension). Within each group/question combination, there's multiple answer choices (3rd dimension), and then I tally the votes and related statistics per each answer choice (4th dimension). (It's actually combining two database tables.)

I've noticed the load times have quickly escalated. But I'm sure I can come up with an object oriented solution.

I think I'll make each group an object, with the different questions as the fields. The answer choices / statistics will probably be a two-dimensional array (perhaps I could make it one somehow). This should be much more manageable.

Thanks a lot!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.