Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 866221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:46:10+00:00 2026-05-15T09:46:10+00:00

I am writing a recursive function to print out the differences between 2 multildimensional

  • 0

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.

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.

Note: Changes since original post based on comments
Added a default level= ”
Removed comments between the if{} elseif{} blocks
Removed an else; at the end of the block that had no function
Encoded the < and > symbols so angle bracket would show in my code

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 "<br>" . $level . $key ."=>" . $value1 . "as array, compared to  ". $value2 ."<br>";
      }
      elseif($value1 != $value2){                      // the values don't match, print difference
        print "<br>" . $level . $key ."=>" . $value1 ." != " . $value2 ."<br>";
      }
    }
    else{                                              
      print "<br>" . $level. $key . "does not exist in array2";
    }
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:46:11+00:00Added an answer on May 15, 2026 at 9:46 am

    It works fine for me here. I put your function (with the tiny difference of adding a default value of ” to the level parameter), and these two arrays:

    $a1 = array('foo', 'bar', 2, array('baz', '3', 4, array(54,45)));
    $a2 = array('faz', 'bar', 4, array('buz', '3', 5, 54));
    

    And got this output:

    0=>foo != faz
    
    2=>2 != 4
    
    [ 3 ]0=>baz != buz
    
    [ 3 ]2=>4 != 5
    
    [ 3 ]3=>Arrayas array, compared to  54
    

    Perhaps your starting arrays are not what you think they are…?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing this code that one function calls itself recursively. But I am
writing a recursive string reverse function out of curiosity, but having a bit of
I'm writing a C code for improving recursive functions learning. My function must calculate
For personal use I am currently writing a recursive PHP function that should process
I'm writing this function which I want to print all the sublists of a
This is my first ever attempt at writing a recursive function in c. The
I'm writing a recursive function in Ocaml that's supposed to count the number of
Say we're writing a simple recursive function fib(n) that calculates the nth Fibonacci number.
I'm writing a recursive function in JS and having some trouble. Let's start with
I'm writing a recursive function to construct a multidimensional array. Basically, the problem is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.