我有这个数组,例如(大小是可变的):
x = ["1.111", "1.122", "1.250", "1.111"]
Run Code Online (Sandbox Code Playgroud)
我需要找到最常用的值("1.111"在这种情况下).
有一个简单的方法吗?
事先提前!
编辑#1:谢谢大家的答案!
编辑#2:我根据ZED的信息更改了我接受的答案.再次感谢大家!
我有这个(简化的)表结构:
users
- id
- type (institutions or agents)
institutions_profile
- id
- user_id
- name
agents_profile
- id
- user_id
- name
Run Code Online (Sandbox Code Playgroud)
我需要profile在Users模型上创建一个关系,但以下方法不起作用:
class User extends Model
{
public function profile()
{
if ($this->$type === 'agents')
return $this->hasOne('AgentProfile');
else
return $this->hasOne('InstitutionProfile');
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么能实现这样的目标?