Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP elseif statement not executed even though initial if statement is false
    primarykey
    data
    text
    <p>I am writing a recursive function to print out the differences between 2 multildimensional php arrays. The purpose of this code is to see the difference between jpeg headers to deteremine how adobe bridge cs3 is saving rating information within the jpg file.</p> <p>When I am single-stepping through the code using my eclipse - zend debugger ide, it appears that even though the initial if statement is false (ie neither values is an array), the subsequent elseif statements are never executed. The function is attached below.</p> <p>Note: Changes since original post based on comments<br> Added a default level= ''<br> Removed comments between the if{} elseif{} blocks<br> Removed an else; at the end of the block that had no function Encoded the &lt; and &gt; symbols so angle bracket would show in my code</p> <pre> function array_diff_multi($array1,$array2,$level=''){ $keys = array_keys($array1); foreach($keys as $key) { $value1 = $array1[$key]; if(array_key_exists($key,$array2) ){ $value2 = $array2[$key]; if (is_array($value1) && is_array($value2)){ // Check if they are both arrays, if so recursion is needed array_diff_multi($value1,$value2,$level . "[ " . $key . " ]"); } elseif(is_array($value1) != is_array($value2)){ // Recursion is not needed, check if comparing an array to another type print "&lt;br&gt;" . $level . $key ."=>" . $value1 . "as array, compared to ". $value2 ."&lt;br&gt;"; } elseif($value1 != $value2){ // the values don't match, print difference print "&lt;br&gt;" . $level . $key ."=>" . $value1 ." != " . $value2 ."&lt;br&gt;"; } } else{ print "&lt;br&gt;" . $level. $key . "does not exist in array2"; } } } </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload