我想在以下数组上创建一个克隆函数,
$usernames = array ( 'jack', 'amy', 'chris');
这样:
克隆 jack,将导致 jack-1(因为 jack-1 在 usernames 数组中尚不存在)。克隆后,用户名数组应更新为:
$usernames = array ( 'jack', 'amy', 'chris', 'jack-1');
Cloning jack, (again) would result in jack-2
Cloning jack-1, would result in jack-1-1
Cloning jack-1-1, would result in jack-1-1-1
Cloning jack-1-1 (again), would result in jack-1-1-2
Cloning jack-1-1-1 would result in jack-1-1-1-1
等等等等..
我可以使用 in_array 来做到这一点,但要寻找一种有效的方法来做到这一点。
谢谢,