php - array_diff not returning what's expected -


i've read tutorials on here none of them return need. have 2 arrays.

$arraya = array(1960,1961,1963,1962,1954,1953,1957,1956,1955); $arrayb = array(1949,1960,1961,1963,1962,1954,1953,1957,1956,1955); 

however, when run array_diff, returns empty array.

$diff = array_diff($arraya, $arrayb); 

but i'd return 1949. what's error in code?

edit: since switching variables won't work, did var_dump 3 arrays (a, b, , diff) , here's pastebin http://pastebin.com/tn1dvcs3

array_diff works finding elements in first array aren't in second, per documentation. try inverting call:

$diff = array_diff($arrayb, $arraya); 

to see in action, lets @ more manageable equivalent example:

$arraya = array(1960); $arrayb = array(1949,1960);  $diff = array_diff($arrayb, $arraya); var_dump($diff); 

this yields:

[mylogin@aserver ~]$ vim test.php [mylogin@aserver ~]$ php test.php array(1) {   [0]=>   int(1949) } 

please note uses minimal demonstrative example of functionality you're attempting get. discarding unnecessary data in actual implementation can more 0 in on problem you're having.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -