0

我有这个数组:

$fields = $_GET['r'];

其中有一些 id,例如:

Array (
[0] => 3134
[1] => 3135 )

然后我在 $tematiche 中有这个字符串:

3113,3120

如何在第一个数组中标记这个字符串?另外,如何删除equals id(如果有)?

4

4 回答 4

1

试试这个 :

$fields = $_GET['r'];
$string = '3113,3120';

$array  = explode(",",$string);
$res_array  = array_unique(array_merge($fields,$array));

echo "<pre>";
print_r($res_array);

输出 :

Array (
[0] => 3134
[1] => 3135 
[2] => 3113
[3] => 3120
)
于 2013-02-27T08:54:41.120 回答
1

尝试,

$fields = array_unique(array_merge($fields,explode(",",$tematiche)));
echo "<pre>";
print_r($fields);
于 2013-02-27T08:56:13.627 回答
0

和的组合是合适explode()的。array_merge()array_unique()

// Make $tematiche into an array
$tematiche_array = explode(',', $tematiche);
// Merge the two arrays
$merged_array = array_merge($fields, $tematiche_array);
// Remove all duplicate values in the array
$unique_array = array_unique($merged_array);
于 2013-02-27T08:55:29.267 回答
0

请像这样尝试。这应该适合你。

$a = explode(',', '3113,3120');
print_r(array_merge($fields,$a));
于 2013-02-27T08:55:36.150 回答