2015-01-26 47 views
0

所以我敲我的頭在牆上的最後2天 所以我的問題是,這條線

ELSEIF($ current_user-> ID == $ bhistory [「用戶id」])

我希望用戶得到錯誤,如果他們的$ 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>"; 
    } 
    } 

小號

+0

http://php.net/foreach – 2015-01-26 22:08:17

回答

0

我會試着解釋你要求的一行例子如下:

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

} 

對於$ bidding_hi中的每個元素通過關鍵字$ kk('a','b')確定的故事選擇$ bidding_history [$ kk]的值。

這將輸出類似的東西: 第一循環:$ KK = 'a' 和$ bhistory =陣列( '1', '2') 第二循環:$ KK = 'b' 和$ bhistory =陣列('3','4')

我不會說流利的英語,但我希望我說得很清楚。

+0

非常感謝,您幫助我瞭解導致解決問題的foreach功能。感謝隊友 – 2015-01-27 19:14:05

+0

我很高興這對你有幫助。 – 2015-01-27 20:01:00

1

首先,您應該控制它是否爲空。

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']; 
0

你可以試試這個來檢查當前用戶相同的最後一個數組中

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