vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Foreach loop with vb condition on multidimensional array (https://vborg.vbsupport.ru/showthread.php?t=315003)

joshtrav 10-21-2014 04:48 PM

Foreach loop with vb condition on multidimensional array
 
Long title, heh.

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

Code:

                <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.


All times are GMT. The time now is 01:10 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00949 seconds
  • Memory Usage 1,711KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete