I have an array called $mydata that looks like this:
Array
(
[0] => Array
(
[id] => 1282
[type] =>2
)
[1] => Array
(
[id] => 1281
[type] =>1
)
[2] => Array
(
[id] => 1266
[type] =>2
)
[3] => Array
(
[id] => 1265
[type] =>3
)
)
I’ve assigned the array to smarty $smarty->assign("results", $mydata)
Now, in the template, I need to print how much of each “type” there is in the array. Can anyone help me do this?
PHP 5.3, 5.4:
As of Smarty 3 you can do
You can also pipe it in Smarty 2 or 3:
To count up “type” values you’ll have to walk through the array in either PHP or Smarty:
PHP 5.5+:
With PHP 5.5+ and Smarty 3 you can use the new
array_columnfunction: