1

我有这样的对象:

class Log
{
    public matches;

    public function __construct()
    {
        $this->matches = array();
    }
}

class Match
{
    public owner;
    public stuff;
}

在我的整个程序中,我将数据存储到$owner$stuff通过遍历 Log 对象的数组匹配来访问它。我想知道的是如何获得一个包含所有唯一所有者列表的数组。

例如,如果我有以下信息:

Bill SomeStuff
Bob SomeOtherStuff
Stan MoreOtherStuff
Bill MoreOfBillsStuff
Bill BillhasLotsofStuff

如何获取仅包含Bill, Bob,的数组Stan

4

1 回答 1

0

这是一个示例函数,您可以将其添加到Log类中以返回所有者列表:

function getOwners()
{
    $owners = array();
    foreach($this->matches as $match)
    {
        $owners[$match->owner] = 0;
    }

    return array_keys($owners);
}
于 2011-11-08T19:50:12.010 回答