2
我想知道如何在數組b1和b2中動態添加數組,因爲如果條件被調用超過一次,那麼b1會覆蓋自身,b2也是如此。動態數組再次覆蓋
$sql = "SELECT senderid , receiverid,request FROM friendrequest WHERE request = '1'";
$result = mysqli_query($con,$sql);
$u1 = array();
$u2 = array();
$b1 = array();
$b2 = array();
while ($row =mysqli_fetch_array($result)){
if(($row['senderid']==$senderid)){
$value = $row['receiverid'];
$u1['receiverid']=$value;
$b1 = array($u1['receiverid']);
}else if(($row['receiverid']==$senderid)){
$value = $row['senderid'];
$u2['senderid']=$value;
$b2 = array($u2['senderid']);
}
$b=array_merge($b1,$b2);
}
我也嘗試了另一個邏輯代碼,但它給了我錯誤。
$sql = "SELECT senderid , receiverid,request FROM friendrequest WHERE request = '1'";
$result = mysqli_query($con,$sql);
$u1 = array();
$u2 = array();
$b1 = array();
$b2 = array();
$f1=0;
$f2=10;
while ($row =mysqli_fetch_array($result)){
$f1=$f1+1;
if(($row['senderid']==$senderid)){
$value = $row['receiverid'];
$u1['receiverid']=$value;
$b1[$f1] = array($u1['receiverid']);
}else if(($row['receiverid']==$senderid)){
$value = $row['senderid'];
$u2['senderid']=$value;
$b2[$f1] = array($u2['senderid']);
}
$b=array_merge($b1,$b2);
}
不,它不工作 – Shubham
你想最終的陣列看起來像什麼? – bloodyKnuckles
人們沒有迴應。 –