函数文档

bool_from_yn()

💡 云策文档标注

概述

bool_from_yn() 是一个 WordPress 函数,用于判断输入是否为 'y'(是)或 'n'(否),并返回布尔值。

关键要点

  • 函数接受一个字符串参数 $yn,必须是 'y' 或 'n'。
  • 返回 true 当输入为 'y'(不区分大小写),否则返回 false。
  • 函数源码基于 strtolower() 进行大小写不敏感比较。

代码示例

function bool_from_yn( $yn ) {
	return ( 'y' === strtolower( $yn ) );
}

📄 原文内容

Determines whether input is yes or no.

Description

Must be ‘y’ to be true.

Parameters

$ynstringrequired
Character string containing either 'y' (yes) or 'n' (no).

Return

bool True if 'y', false on anything else.

Source

function bool_from_yn( $yn ) {
	return ( 'y' === strtolower( $yn ) );
}

Changelog

Version Description
1.0.0 Introduced.