WordPress 函数:wp_parse_id_list 整理理数组、逗号或空格分隔的ID列表

江河/ 2023年10月29日/ WordPress/ 浏览 474

函数原型:


wp_parse_id_list( array|string $input_list ): int[]


清理数组、逗号或空格分隔的ID列表。


参数说明:


$input_list,ID列表(字符串,或数组)


函数源码:


function wp_parse_id_list( $input_list ) {
	$input_list = wp_parse_list( $input_list );

	return array_unique( array_map( 'absint', $input_list ) );
}


使用举例:


// 结果 $result 是 [0 => 1, 2 = > 2, 4 => 3]
$result = wp_parse_id_list('1,1,2,2,3,3');


发表评论

暂无评论,抢个沙发...

客服 工单