0

I have this array:

$fields = $_GET['r'];

Which has some ids, for example:

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

and then I have this string in $tematiche:

3113,3120

How can I marge this string in the first array? Also, how can I remove the equals id (if any)?

1
  • 1
    implode(",", $_GET["r"]); see implode() Commented Feb 27, 2013 at 8:52

4 Answers 4

1

Try,

$fields = array_unique(array_merge($fields,explode(",",$tematiche)));
echo "<pre>";
print_r($fields);
Sign up to request clarification or add additional context in comments.

Comments

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
)

1 Comment

Edited the code now you will get all unique values array_unique(array_merge($fields,$array));
0

A combination of explode(), array_merge() and array_unique() would be suitable.

// 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);

Comments

0

Please try like this. This should work for you.

$a = explode(',', '3113,3120');
print_r(array_merge($fields,$a));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.