为什么我的WordPress插件选项数组不工作


Why my WordPress plugin options array not working

我的php变量$ex_product_ids包含值18,63,72,91 &我使用echo $ex_product_ids检查了它,它正确显示了我的插件输入字段的值,但是当我想在$target_products = array($ex_product_ids);这样的数组中使用它时,它不工作,只返回第一个数组项的结果。

这里是代码不工作

$_options = get_option( 'license_page_option' ); 
$ex_product_ids = $_options['ex_product_ids_warranty']; // it have value 18,63,72,91
$target_products = array($ex_product_ids);

但是如果我手动使用这些id,比如$target_products = array(18,63,72,91);,它可以工作

如果我做错了什么,我很抱歉!请帮助

我认为你需要使用爆炸(),因为当前值可以是简单的字符串,你需要将其转换为值数组。

$_options = get_option( 'license_page_option' ); 
$ex_product_ids = $_options['ex_product_ids_warranty']; // it have value 18,63,72,91
$target_products = explode(",",$ex_product_ids);
print_r($target_products); // array(18,63,72,91)