0

私はこの配列を持っています:

$fields = $_GET['r'];

たとえば、いくつかのIDがあります。

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

そして、$tematiche に次の文字列があります。

3113,3120

この文字列を最初の配列にマージするにはどうすればよいですか? また、等号 ID (ある場合) を削除するにはどうすればよいですか?

4

4 に答える 4

1

Try this :

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

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

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

Output :

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 に答える