gpt4 book ai didi

php - 功能在服务器上不起作用。不能在写上下文中使用函数返回值

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:34:57 24 4
gpt4 key购买 nike

我正在使用此功能检查某些产品是否在我的 woocommerce 购物车中。这适用于我的本地主机,但给了我一个:

Can't use function return value in write context

在服务器上。

function product_is_in_the_cart() {
$ids = array( '139, 358, 359, 360' );

$cart_ids = array();

// Find each product in the cart and add it to the $cart_ids array
foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
$cart_product = $values['data'];
$cart_ids[] = $cart_product->id;
}

// Si uno de los productos introducidos en el array esta, devuelve false
if ( ! empty( array_intersect( $ids, $cart_ids ) ) ) {
return true;
} else {
return false;
}}

我正在尝试寻找其他方法来执行此操作,但我找不到问题的答案,我认为是因为 empty() 但我如何通过其他方式执行此操作?

最佳答案

我看到这是标记为 php 5.3

在 5.5 之前的 php 版本中 empty()将只接受一个变量。您需要先像这样分配它:

$isEmpty = array_intersect($ids, $cart_ids);

if ( !empty($isEmpty) ) {
...
}

关于php - 功能在服务器上不起作用。不能在写上下文中使用函数返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34433714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com