recursion - PHP elseif statement not executed even though initial if statement is false -
I am writing a recursive function to print the difference between 2 multilayer php arrays. The purpose of this code is to see the difference between jpeg header for detarrine how the Adobe Bridge is saving rating information within the cs3 jpg file
When I am using my eclipse through the code Make Single Step - Zend Debugger IDE, It seems that if the initial statement is false (i.e. neither value is an array), otherwise the statements are never executed otherwise. Functions are attached below.
Note: Changes since the original post on the basis of comments - added a default level = ''
if deleted entries between blocks {} elseif {} block removed / removed one more ; No function at the end of the block & lt; And & gt; Therefore angle bracket symbols will be displayed in my code
function array_diff_multi ($ array1, $ array2, $ level = '') {$ key = array_keys ($ array1); Forex currency ($ key as $ key) {$ value1 = $ array1 [$ key]; If (array_key_exists ($ key, $ array2)) {$ value2 = $ array2 [$ key]; If (if_array ($ value1) && is_array ($ value2)) {// If they are doing both arrays, check that if there is a repatriation requirement, array_diff_multi ($ value1, $ value2, $ level . "[". $ Key. "]"); } Elseif (is_array ($ value1)! = Is_array ($ value2)) {// Do not require recurrence, check that an array compares in another type "
To do. $ Level $ key "$ Value 2" compared to array in comparison to "=>" $ Value1 " "& Lt; br & gt;"; } Otherwise ($ value1! = $ Value2) {// values do not match, print difference print ""
" . $ Level $ key "=>" $ Value1 "! =" $ Value2. "& Lt; br & gt;"; }} Other {Print "& lt; br & gt;" . $ Level $ Key "does not exist in array 2"; }}}
This works fine for me here I enter my function (with the small difference of adding a default value of '' in the level parameter), and these two arrays:
$ a1 = array ('foo', 'bar' , 2, array ('falcon', '3', 4, array (54,45)); $ A2 = array ('fuzz', 'bar', 4, array ('buz', '3', 5, 54));
and found this output:
0 = & gt; Foo! = Faz 2 = & gt; 2! = 4 [3] 0 = & gt; Buzz! = Buz [3] 2 =>! 4 = 5 [3] 3 = & gt; Arrayas array, comparison of 54
Maybe your starting arrays are not what you think they are doing. ..?
Comments
Post a Comment