PDA

View Full Version : Foreach loop with vb condition on multidimensional array


joshtrav
10-21-2014, 04:48 PM
Long title, heh.

I have a foreach loop iterating through a predefined multidimensional array.


<vb:each from="bans" key="banid" value="k">
<vb:if condition="$bans.$k['duration'] != False">
<td>{vb:raw k.ban_duration}</td>
<vb:else />
<td>&infin;</td>
</vb:if>
</vb:each>


I am trying to properly evaluate $k["duration"] but cannot. Even when assigned false it will evaluate true in some cases, or false on all in other attempts.

I have tried the following

$bans[$banid]['duration'],
$bans['banid']['duration'],
$bans[banid]['duration'],
$bans[$banid].duration,

etc.,

I have been at it for hours and can't seem to get it to evaluate properly.

I have also tried different options using $k['duration'], etc.

If anyone can shed some light on this it would be greatly appreciated.

Dave
10-21-2014, 05:50 PM
You can not use those variables directly in a vBulletin if statement as far as I know.
Would something like banid[k]['duration'] work? Probably not but worth a shot.

An easier way to approach this is by setting a variable to true or false in the actual PHP script which produces the $bans array.

kh99
10-21-2014, 06:24 PM
If "bans" is an array of arrays, then I think you should be able to use $k['duration'] (or k.duration in a template tag). I'm not 100% sure about the $k in a condition because I've never tried it.

I'm not sure why you're having an issue with it being true sometimes when set to false. You could try checking using "!==False" to make sure it's not something else that converts to false, but if you're setting it to False it definitely shouldn't be true.

It might help if you can show us some of the relevant php.