Link to home
Start Free TrialLog in
Avatar of joomla
joomlaFlag for Australia

asked on

output php multi-dimensional array

I've tried to create a multi dimensional array (see below) but I'm having trouble outputting it.

Array ( [prods] => Array ( [0] => Array ( [0] => Polo X [1] => [2] => [3] => [4] => [5] => ) ) [sizes] => Array ( [0] => Array ( [0] => S [1] => [2] => [3] => [4] => [5] => ) ) [qtys] => Array ( [0] => Array ( [0] => 9 [1] => [2] => [3] => [4] => [5] => ) ) [totals] => Array ( [0] => Array ( [0] => 876 [1] => 876 [2] => 876 [3] => 876 [4] => 876 [5] => 876 ) ) )

I created it as follows  (where $errorProds is an array)
            $errorStocks = array(
            "prods"=>array($errorProds),
            "sizes"=>array($errorSizes),
            "qtys"=>array($errorQtys),
            "totals"=>array($errorStocks))      ;

I'd like to output it as a list
prods1, sizes1, qtys1, totals1
prods2, sizes2, qtys2, totals2
etc...

thanks
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joomla

ASKER

Hi,
can you tell me how I could create the array better.

I have a function that generates four arrays or lists of data that I want to return to the calling routine.

I'm much rather take more time to pass the content from the function to the routine in the most efficient way

thanks
M
"can you tell me how I could create the array better."

I am not sure what you mean by this. The method you are using is OK, I just found it a little odd that you had an "array of an array of arrays" rather than the simpler "array of arrays".

My own preference would be to create a small class just to hold the data and then build an array of class objects which I would then pass to the output function, but that is really a whole separate question and completely invalidates the answer to this question.

It is not that hard to do. I have an EE article that shows the outlines of it and if you want to post a sepearte question on it then I will show you how to approach it for this specific problem

https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_3212-Using-PHP-classes-to-group-data-in-memory.html
Avatar of joomla

ASKER

thanks for the additional infomation
exactly what I need to get a handle on it