Re: [SMARTY] How to access associative array by a variable key?
| From: | Damien Messner | Date: | Mon, 07 Mar 2005 22:15:59 +0000 |
| Subject: | Re: [SMARTY] How to access associative array by a variable key? | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-12300@lists.php.net to get a copy of this message | ||
Mike Zornek a écrit :
I have created an array in php like: $columns = array(); $types = array(); $values = array();$columns['1'] = "member_current_category_id"; $types['1'] = "is"; $values['1'] = "1"; $columns['2'] = "member_current_category_id"; $types['2'] = "is"; $values['2'] = "2";I keep track of how many sets I have with: $criteria_count = 2; And have assigned them to my Smarty template ala: $smarty->assign_by_ref("columns", $columns); $smarty->assign_by_ref("types", $types); $smarty->assign_by_ref("values", $values); $smarty->assign_by_ref("criteria_count", $criteria_count); In the template I use a section to loop through to create hidden fields to hold the data: {section name="myLoop" start=1 loop=$criteria_count} <input type="hidden" id="search_column_{$smarty.section.myLoop.index}" name="search_column_{$smarty.section.myLoop.index}" value="" /> <input type="hidden" id="search_type_{$smarty.section.myLoop.index}" name="search_type_{$smarty.section.myLoop.index}" value="" name="search_value_{$smarty.section.myLoop.index}" value="" /> {/section} My problem is I can't figure out how to get the values out of the array, as I need to use a variable key. Any suggestions? Thanks in advance. ~ Mike ----- Mike Zornek Web Designer, Media Developer, Programmer and Geek Personal site: <http://MikeZornek.com> simply do that:
$columns[] = "member_current_category_id"; $types[] = "is"; $values[] = "1"; $columns[] = "member_current_category_id"; $types[] = "is"; $values[] = "2";{section name=inc loop=$columns} <input type="hidden" id="search_column_{$smarty.section.inc.iteration}" name="search_column_{$smarty.section.inc.iteration}" value="{$columns[inc]}" /> <input type="hidden" id="search_type_{$smarty.section.inc.iteration}" name="search_type_{$smarty.section.inc.iteration}" value="{$types[inc]}" name="search_value_{$smarty.section.inc.iteration}" value="{$values[inc]}" /> {/section} but you must have the same size for the array types, values an columns otherwise you may have problem. But in this cas, it will work fine...