简体   繁体   English

字符串数组中的唯一字符串

[英]unique string from array of strings

I want to create a string that is unique from all the strings in an array. 我想创建一个与数组中所有字符串唯一的字符串。 I know that unique_array would create an array with unique values, but I want to create a new string that is unique from all the strings in the unique array. 我知道unique_array会创建一个具有唯一值的数组,但是我想创建一个新字符串,该字符串与唯一数组中的所有字符串都是唯一的。 I want this in PHP. 我想要在PHP中。

For example, if I have "1" , "2" strings in the unique array. 例如,如果我在唯一数组中有"1""2"字符串。 I would like to create a "3" string or "a" string or any other string with a different name then "1" , and "2" . 我想创建一个"3"字符串或"a"字符串或其他名称不同于"1""2"其他字符串。 Serialize a new string and add it into the array and check for unique_array sounds like it should work, but is there a simpler way to do it? 序列化一个新字符串,并将其添加到数组中,并检查是否应该起作用,以检查unique_array声音,但是有没有更简单的方法呢?

How about 怎么样

sort($array);
$array[] = end($array) + 1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM