Access to the two-dimensional array in the template

Hugilore111

Member
Hello!
I have a two-dimensional array
Code:
Array
(
    [0] => Array
        (
            [enter_id] => 1
            [user_id] => 1
            .....
)
[1] => Array
        (
            [enter_id] => 2
            [user_id] => 1
            .....
       )
)

How to walk in a series of two-dimensional array in a template?
I'm trying to do
Code:
<xen:foreach loop="$entr" key="$key" value="$val" >
    {xen:raw $val.messageHtml}
</xen:foreach>
I get template empty array
Array()
 
Last edited:
Be sure you pass $entr from your PHP to the template.

Then it's...
Code:
<xen:foreach loop="$entr" value="$entrvalue">
   {xen:raw $entrvalue.messageHtml}
</xen:foreach>
 
There is something wrong with your array then. I tested this by creating an array in PHP and passing it to a template..
Code:
$entr = array(array('a' => 'This is a', 'b' => 'This is b'),array('a' => 'This is 1c', 'b' => 'This is 1d'));

And put this code in the template (your original code)...
HTML:
{xen:helper dump,$entr}
<br />
<xen:foreach loop="$entr" key="$key" value="$entrvalue">
   {xen:helper dump,$entrvalue}
   {xen:raw $entrvalue.a}
   <br /><br />
</xen:foreach>

And the results printed without a problem...
Code:
array(2) {
  [0] => array(2) {
    ["a"] => string(9) "This is a"
    ["b"] => string(9) "This is b"
  }
  [1] => array(2) {
    ["a"] => string(10) "This is 1c"
    ["b"] => string(10) "This is 1d"
  }
}


array(2) {
  ["a"] => string(9) "This is a"
  ["b"] => string(9) "This is b"
}

This is a 

array(2) {
  ["a"] => string(10) "This is 1c"
  ["b"] => string(10) "This is 1d"
}

This is 1c
 
Million times i open this page, copy something and change it to:

<xen:foreach loop="$something" key="$key" value="$val" >
{$key} :: {$val}
</xen:foreach>
 
Back
Top Bottom