Skip to content
Advertisement

List values in multi-dimensional array in php

I have been working on this a while. I see multi-dimensional arrays in php are not that easy. Here is my code:

JavaScript

This works well to display the keys of the main array. what I get is :

JavaScript

What I want is the visitors and the value (number of visitors), value of actions, etc. I want to then save the value in Mysql. Some I will have to convert from a string to and int or date.

I need to list one more level deep. But I cannot see how to do this. ————–Added ———– So what I have is an array of arrays. I need to step through each array.

Advertisement

Answer

did you try print_r ?

if you need more control over formatting then embedded loops as suggested by @Nick is the best option. Although it would be more natural and safer to use foreach loops rather than while.

JavaScript

see PHP manual: each , there is a “caution” frame.

EDIT 1 I update sample code above for 2 day array.

It seems your array has more than 2 dimension. Then you should use recursion.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement