Good day. I use the Fenom template engine and in it I output an array with the template settings including the sidebar list. Where the tab data is stored. enter image description here

Since it is located in the array under the array, the code is:

{foreach $sidebar as $key => $value} <div>{$key} : {$value}</div> {/foreach} 

I get

 0 : Array 1 : Array 2 : Array 3 : Array 
  • Help solve this problem and what should I do with it. I receive the data array through: mysqli_fetch_all with the parameter MYSQLI_NUM - No0k
  • It is not entirely clear that you are not satisfied, the conclusion is quite logical, the key and value are output, the value is an array, if you want to get something from this array, refer to the keys of the array. I did not work with the template engine, but judging from the documentation - {$value.name} or {$value['name']} , it will display the category name from the array. - Bookin

1 answer 1

In general, iterate over and nested arrays to get the result.

 {foreach $sidebar as $key => $value} {foreach $sidebar as $_key => $_val} {$_key} : {$_val} {/foreach} {/foreach} 

as well as in php

 {foreach $sidebar as $key => $value} {$value['id']} {/foreach} 

see the doc https://github.com/fenom-template/fenom/blob/master/docs/ru/syntax.md#%D0%9C%D0%B0%D1% 81% D1% 81 D0% B2% D1% 8B

  • This code works. But just gives out all the keys and values: link You can tell how to take a particular key and its values. For example id - No0k