html_options function

This function can specify which elements are selected. Either the values ​​and ouput attributes must be specified, or the options substitution must be specified.

If the given value is an array, it will be used as OPTGROUP processing, and supports recursion. All output is XHTML compatible.

If the optional attribute name is specified, the option list will be placed in <select name="groupname"></select> tag alignment. If not specified, only a list of options will be generated.

Other parameters not mentioned in the above table are in <select> ; Displayed in the tag as a "name/attribute" pair. If the optional attribute name is not specified These parameters will be ignored.

eg1:

test.php:

require( 'Smarty.class.php');
$smarty = new Smarty;
$smarty->assign('cust_ids', array(1000,1001,1002,1003));
$smarty- >assign('cust_names', array('Joe Schmoe','Jack Smith','Jane
Johnson','Carlie Brown'));
$smarty->assign('customer_id', 1001 );
$smarty->display('test.html');

test.html:

##<select name=customer_id> {html_options values=$cust_ids selected=$customer_id output=$cust_names}
</select>




eg2:

test.php:
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->assign('cust_options', array(
1001 => 'Joe Schmoe',
1002 => 'Jack Smith',
1003 => 'Jane Johnson',
1004 => 'Charlie Brown'));
$smarty->assign('customer_id', 1001);
$smarty->display('test.html');

test.html:
<select name=customer_id>
{html_options options=$cust_options selected=$customer_id}
</select>


输出: 
<select name=customer_id>
<option value="1000">Joe Schmoe</option>
<option value="1001" selected="selected">Jack Smith</option>
<option value="1002">Jane Johnson</option>
<option value="1003">Charlie Brown</option>
</select>

微信图片_20180313114508.png

Continuing Learning
||
<?php echo "html_options函数";
submitReset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!