-1

初心者なので質問があります

さて$nUserID、ユーザーのIDを保存する場所があり、

int(1)
int(2)
int(1)

そして、$nAuctionID私にはアイテムIDがあり、それらは次のようになります

int(150022)
int(150022)
int(150031)

私はそれを1つの配列に入れて、それを好きにする必要があります

array (

[1] => 150022
[2] => 120022,150031

)

どのユーザーがどのアイテム ID を見ているか

どうやってするか ?

foreach を使用する必要がありますが、どのように見えるか想像できません

皮切りに

 $u[] = $nUserID;
 $i[] = $nAuctionID;`
4

3 に答える 3

1

それらをユーザー ID でグループ化すると、探しているものが次のようになります。

$usersWatching = array();

// The following results in:
// array(1 => array(150022, 150023), 2 => array(150022))
// Which should be way more useful.
foreach ($nUserID as $i => $userID)
{
    if (!isset($usersWatching[$userID]))
        $usersWatching[$userID] = array();

    $usersWatching[$userID][] = $nAuctionID[$i];
}

// To get the comma-separated version, do this:
$usersWatching = array_map(function ($value) {
    return implode(',', $value);
}, $usersWatching);
于 2013-08-21T17:10:42.130 に答える
1

これはうまくいきます:

$arr = array();
foreach( $nUserID as $key=>$value)
{
   $arr[$value] =  $nAuctionID[$key] ;
}
print_r($arr);
于 2013-08-21T09:35:00.663 に答える
0

最も紛らわしい言葉遣いの質問EVA!

$outputArray = array();

for ($i=0; $i< count($nUserID); $i++) {
    $outputArray[$nUserID[$i]] = $nAuctionID[$i];
}

echo "<pre>";
print_r($outputArray);

それがあなたの質問から得たものです..

于 2013-08-21T09:35:18.700 に答える