2

the below are the array am getting out i want to mearge array and remove duplicats of it and pass too for loop not able too do i just want is remove duplicate and pass too for loop as a unique value

i tried with print_r(array_merge($uniq_arr));

for($i = 0; $i < count($uniq_arr); $i++) {

                        $tag = $uniq_arr[$i];
}

Array
(
    [0] => diet
    [1] => exercise
)
Array
(
    [0] => diet
    [1] => exercise
)
Array
(
    [0] => diet
    [1] => exercise
)
Array
(
    [0] => water intake
    [1] => hygiene
    [2] => diet
)

Out put in tag shold be like each unique value

2
  • Are they separate arrays, or arrays in one larger array? Commented Mar 28, 2017 at 0:35
  • array in large array they are different array after meargin them i got this array Commented Mar 28, 2017 at 0:38

2 Answers 2

2

You could just use array_merge() indiscriminately then use array_unique() to remove any duplicate entries.

Sign up to request clarification or add additional context in comments.

5 Comments

@shaik - array_unique will not work on nested arrays as one may expect. If this is what you're referring to then you may need to give additional details as to what your initial data set looks like. If you have 4 arrays which contain strings you should be able to use array_merge() to create one array of all your strings before using array_unique() to remove duplicate entries
i did added a array merge
se for me in my database i mage multiple values they are tag stored wht i want too do its check multiple tags with my unique tag table and show the only tags that are present in tag post table
@Shaik - Can you edit your question to include that code?
can u join me on team viewer or skype i vl share u my screen ?
0

Here is how you could implement the array_merge, array_unique solution. I am making an assumption that you have 4 arrays like so:

$tag1Array = array('diet','exercise');
$tag2Array = array('diet','exercise');
$tag3Array = array('diet','exercise');
$tag4Array = array('water intake','diet','exercise');

$commontags = array_unique(array_merge($tag1Array,$tag2Array,$tag3Array,$tag4Array));

This should result in a single array of the unique values present in any of the 4 tag arrays.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.