I have the following Array...
Array
(
[main] => Array
(
[0] => Array
(
[id] => 1
[name_one] => banana
[name_two] =>
)
[1] => Array
(
[id] => 2
[name_one] => orange
[name_two] => banana
)
[2] => Array
(
[id] => 3
[name_one] =>
[name_two] => orange
)
[3] => Array
(
[id] => 4
[name_one] => pear
[name_two] =>
)
[4] => Array
(
[id] => 5
[name_one] => pear
[name_two] => mango
)
[5] => Array
(
[id] => 6
[name_one] =>
[name_two] =>
)
)
)
the logic behind is the following, If the field "name_two" is not empty ignor "name_one" and count only "name_two". If the field "name_two" is empty the take "name_one" and count. If both are empty..No count.
The result from the above array should look like the following table...
------------------------------
category | total
------------------------------
banana | 2
-----------------------------
orange | 1
-----------------------------
pear | 1
-----------------------------
mango | 1
-----------------------------
Total | 5
I have tried different method including foreach, for and while loop in php but no luck...How do i achieve the table above in php?
if it is easy, the array structure is changed? you are most welcome to change as you like and i can adapt it here. The main issue is generating the table from the array look like the above structure.