selected()动态判断select的选项设置为选中

目录

描述

For use in select form fields.
Compares two given values (for example, a saved option vs. one chosen in a form) and, if the values are the same, adds the selected attribute to the current option tag.

selected() 描述

用法

<?php selected( $selected, $current, $echo); ?>

selected() 用法

参数

$selected

(mixed) (必填) One of the values to compare.

默认值: None

$current

(mixed) (可选) The other value to compare if not just true.

默认值: true

$echo

(boolean) (可选) Whether to echo or just return the string.

默认值: true

selected() 参数

源文件

selected() 函数的代码位于 wp-includes/general-template.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Outputs the html selected attribute.
 *
 * Compares the first two arguments and if identical marks as selected
 *
 * @since 1.0.0
 *
 * @param mixed $selected One of the values to compare
 * @param mixed $current  (true) The other value to compare if not just true
 * @param bool  $echo     Whether to echo or just return the string
 * @return string html attribute or empty string
 */
function selected( $selected, $current = true, $echo = true ) {
	return __checked_selected_helper( $selected, $current, $echo, 'selected' );
}

selected() 源文件