如何在foreach循环之外破坏多个数组

时间:2016-11-23 19:53:45

标签: php arrays foreach implode

我有一个foreach循环,在循环中我将两行设置为一个数组,这样我就可以在foreach循环之外内爆数组。起初我只有一个阵列内爆,但现在我需要另一个。

我尝试过这样做,但它给出了一个额外的参数错误: ',$ friends_pending_arr,$ friends_pending_img_arr)。

如何将$friends_pending_arr$friends_pending_img_arr同时归入pending_friend_user课程?

变量我想要发生两次内爆。

$pending_friend_list = '<div class="pending-friend-list-row"><div class="pending_friend_user">'. implode
             ('</div><div class="pending_friend_list_decision"><div class="total-center">' . $pending_friend_list_approve . $pending_friend_list_decline . 
             '</div></div></div><div class="pending-friend-list-row"><div class="pending_friend_user">', $friends_pending_arr) .
             '</div><div class="pending_friend_list_decision"><div class="total-center">' . $pending_friend_list_approve . $pending_friend_list_decline . '</div></div></div>';

完整代码:

$pending_friend_list = null;
    $pending_friend_images = null;
    foreach ($pending_friend_rows as $pending_friend_row) {
        $pending_friend_1           = $pending_friend_row['friend_one'];
        $pending_friend_2           = $pending_friend_row['friend_two'];
        $pending_friend_status      = $pending_friend_row['status'];
        $pending_friend_status_date = $pending_friend_row['date'];
        $pending_friend_img         = $pending_friend_row['img'];
        $total_pending_friends      = $pending_friend_1 . "<br>" . $pending_friend_2;

    if ($pending_friend_2 == $user_id) {
        $pending_friend_list_approve = '<img src="../icons/collection/checkmark.png" class="pending_approve_friend" alt="Approve Friend">';
        $pending_friend_list_decline = '<img src="../icons/collection/x-sign.png" class="pending_decline_friend" alt="Approve Friend">';
         $friends_pending_arr[] = $pending_friend_1;
         $friends_pending_img_arr[] = $pending_friend_img;
         $pending_friend_list = '<div class="pending-friend-list-row"><div class="pending_friend_user">'. implode
         ('</div><div class="pending_friend_list_decision"><div class="total-center">' . $pending_friend_list_approve . $pending_friend_list_decline . 
         '</div></div></div><div class="pending-friend-list-row"><div class="pending_friend_user">', $friends_pending_arr) .
         '</div><div class="pending_friend_list_decision"><div class="total-center">' . $pending_friend_list_approve . $pending_friend_list_decline . '</div></div></div>';
    }

0 个答案:

没有答案