计算数组

时间:2017-04-19 04:52:50

标签: php mysql arrays laravel

标题似乎过分简化了这个过程的简单程度,但它真的不容易。我试过解决这个问题,但这很困难

基本上,我有一个items表,一个item_owners表以及它们之间的关系。

items表有大约1.8k的记录,而owner表有大约5.5m的记录

问题是,我试图这样做,以便我可以找到每个项目的所有者具有最多重复,这意味着

如果我们有抢劫,亚当和jon拥有一个名为" Apple"的项目,而jon有3个副本,而rob和adam各有1个,那么让我获得最多重复的人的功能将是乔恩。但那不是它停止的地方,我必须为1.8k记录(项目)执行此操作并通过5.5m项目所有者记录

到目前为止,我已经做到了这一点,但我不知道从哪里开始

public function GetHoards($id){
    //Get all owners

    $OwnersClass = new ROBLOX_Item_Owner;
    $AllOwners = $OwnersClass::all();

    //Get all items

    $ItemsClass = new ROBLOX_Item;
    $AllItems = $ItemsClass:all();

    //Loop through items and store in array

    $Items = array();

    foreach($AllItems as $Item){
        $Items[$Item->id] = array();
    }

    //Loop through owners and store them in items array

    foreach($AllOwners as $Owner){
        array_push($Items, $Owner);
    }

    //Loop through all the items and create a function that gets the owners with the most hoards

    $NewItems = array();

    foreach($Items as $Item){
        foreach($Item as $ItemOwners){
            $result = array_count_values($Item);
        }       
    }

}

这是表格的结构

http://prntscr.com/ey4r4f

0 个答案:

没有答案
相关问题