私はこの配列を持っています:
$fields = $_GET['r'];
たとえば、いくつかのIDがあります。
Array (
[0] => 3134
[1] => 3135 )
そして、$tematiche に次の文字列があります。
3113,3120
この文字列を最初の配列にマージするにはどうすればよいですか? また、等号 ID (ある場合) を削除するにはどうすればよいですか?
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
)
試す、
$fields = array_unique(array_merge($fields,explode(",",$tematiche)));
echo "<pre>";
print_r($fields);
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);
このようにしてみてください。これはうまくいくはずです。
$a = explode(',', '3113,3120');
print_r(array_merge($fields,$a));