Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

When i use array_diff() functions like; $result = array_diff($array1, $array2);

It turns like; Array( [5] => XXXXXX )

But i dont want to show " Array ( "index here" ) ", only XXXXX part. How can i show only XXXXX? Thanks for every comments...

share|improve this question
 
My comment: php.net/array + php.net/array_values + php.net/arrays –  hakre Dec 13 '12 at 20:20
 
What if the difference will be more than one element? What will be XXXXX in that case? array_diff returns an array containing all the entries from array1 that are not present in any of the other arrays. –  Valera Leontyev Dec 13 '12 at 20:21
add comment

closed as not constructive by hakre, KingCrunch, tereško, DavidO, Eric J. Dec 13 '12 at 22:21

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

Obtain the first element that is different -or- NULL if there is no difference.

list($result) = array_values(array_diff($array1, $array2)) + [NULL];

You can do:

var_dump($result);

See Demo.

To just out put the value you can do:

foreach($result as $value){
    echo $value;
}
share|improve this answer
 
it shows only one difference. For example: eval.in/4599 –  ademcu Dec 13 '12 at 20:38
 
Try this eval.in/4804 –  SeanWM Dec 17 '12 at 0:29
 
Did you manage to get this working? If this answer helped, please accept it. –  SeanWM Jan 9 '13 at 19:15
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.