How to access associative array by a variable key?
| From: | Mike Zornek | Date: | Mon, 07 Mar 2005 20:09:33 +0000 |
| Subject: | How to access associative array by a variable key? | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-12299@lists.php.net to get a copy of this message | ||
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>