如果用户是 $x 值上的最后一个用户,则禁用用户交互

disable user interaction if they are the last ones on a $x value

所以在过去的两天里我一直在用头撞墙 所以我的问题是这条线

elseif ($current_user->ID == $bhistory['userid'])

我希望用户得到错误,如果他们是 $bhistory

的最后一个

我的问题是它不起作用,用户是 $bhistory 的最后一个用户,他们仍然可以点击并一次又一次成为 $bhistory 的最后一个用户。

也请有人用英文解释一下这行代码

foreach($bidding_history 作为 $kk => $bhistory){

<?php
global $current_user;
$current_user = wp_get_current_user();
// MAKE BID OPTIONS
if($auction_type != 2){

    // BIDDING DATA
    $BIDDINGSTRING = "";

    // CHECK IF THIS IS AN AFFILIATE PRODUCT OR NOT
    $aff_p = get_post_meta($post->ID,'buy_link',true);
    if(strlen($aff_p) > 1){
    $link_l = get_home_url()."/out/".$post->ID."/buy_link/";
    $btn_l = "<a href='".$link_l."' class='btn btn-primary right'>".$CORE->_e(array('auction','53'))."</a>";

    // STOP BIDDING ON OWN ITEMS & IF LAST BIDDER
    }elseif ($current_user->ID == $bhistory['userid']){
    $btn_l = "<button class='btn' href='javascript:void(0);' onclick=\"alert('".$CORE->_e(array('auction','54'))."');\" id='bid_button'>".$CORE->_e(array('auction','70'))."</button>";
    }else{ if($userdata->ID == $post->post_author) {
    $btn_l = "<button class='btn' href='javascript:void(0);' onclick=\"alert('".$CORE->_e(array('auction','54','flag_noedit'))."');\" id='bid_button'>".$CORE->_e(array('auction','70'))."</button>";
    }else{
    $btn_l = "<button class='btn' href='javascript:void(0);' onclick=\"UpdateBidding();\" id='bid_button'>".$CORE->_e(array('auction','70'))."</button>";
    }
    }

S

我将尝试用一个例子来解释您请求的行:

/*
 * Example: $bidding_history = array(
 *                                  'a'=>array('1','2'),
 *                                  'b'=>array('3','4')
 *                              )
 */
foreach($bidding_history as $kk => $bhistory){

}

对于 $bidding_history 中由键 $kk ('a','b') 标识的每个元素 select $bidding_history[ 的值$kk].

这将输出如下内容: 第一个循环:$kk = 'a' 和 $bhistory = array('1','2') 第二个循环:$kk = 'b' 和 $bhistory = array('3','4')

我的英语不是很流利,但我希望我说清楚了。

首先你要控制它是否为空

if (!empty($current_user) && $current_user->ID == $bhistory['userid'])

foreach;

foreach($bidding_history as $kk => $bhistory)
echo $bhistory['username'];

=

for ($i = 0; $i < count($bidding_history); $i++)
echo $bidding_history[$i]['username'];

您可以试试这个来检查当前用户是否与数组中的最后一个用户相同

$last_user = end($bidding_history)
elseif ($current_user->ID == $last_user['userid']);