PDA

View Full Version : Multi-dimensional arrays in templates.


Sarteck
06-20-2011, 04:57 AM
If I have a multi-dimensional array, how would I go about using it in a template?

For example, let's say I have a regular array of Userinfo. I know that I can get the musername simply by:
{vb:raw userinfo.musername}

Now let's say I have an array called $users. This array has key => value as User ID => Userinfo

Also, let's say I have a variable called $userid.

How would I get the value of $users[$userid]['musername'] in a template?

Would it be as simple as {vb:raw users.{vb:raw userid}.musername}?

--------------- Added 1308564538 at 1308564538 ---------------

I've found this post (https://vborg.vbsupport.ru/showpost.php?p=1916356&postcount=16) by cellarius that says that multidimensional arrays do work in templates, but it doesn't give a example (or say it's even possible) to do something like I mentioned--that is, using a variable as one of the keys of an array.

SiteTalkZone
12-21-2012, 02:08 AM
I have this example how to get the multidimentsional

Example ARRAY:



$Name = Array
(
[0] => Array
(
[0] => Array
(
[firstname] = Bella
[lastname] = Padilla
)
[1] => Array
(
[firstname] = Kim
[lastname] = Tisoy
)
)
[1] => Array
(
[0] => Array
(
[firstname] = Aireen
[lastname] = Sajulgas
)
[1] => Array
(
[firstname] = Kimo
[lastname] = Tanis
)
)
)



Template CODE:

<vb:each from="Name" key="thekey" value="nameset">
<vb:each from="nameset".$thekey value="myname">
{vb:var myname.firstname}
{vb:var myname.lastname}
</vb:each>
</vb:each>



This will print all the firstname and lastname


Hope it helps.