title: PHP: Finding differences in two multidimensional arrays
body: <p>I'm writing a script PHP script that creates a report of all the files of a chosen directory every 24 hours. I want to compare the latest report with the previous report to detect any edits of a file (by comparing md5 hash), deletion of a file, and creation of a file. I have the data of the two reports in two separate arrays. From what I can gather I will have to use the array_diff function. How do I: A) use this with a multidimensional array and B) label if the difference is either an edit, delete, or creation.</p>
  
  <p>Example of data:</p>
  
  <p>New Report:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [file] =&gt; newhotfolder.gif
              [path] =&gt; images/newhotfolder.gif
              [type] =&gt; gif
              [size] =&gt; 1074
              [md5] =&gt; 123812asdkbqw98eqw80hasdas234234
          )
  
      [1] =&gt; Array
          (
              [file] =&gt; image.gif
              [path] =&gt; images/attachtypes/image.gif
              [type] =&gt; gif
              [size] =&gt; 625
              [md5] =&gt; 7bbb66e191688a86b6f42a03bd412a6b
          )
  
      [2] =&gt; Array
          (
              [file] =&gt; header.gif
              [path] =&gt; images/attachtypes/header.gif
              [type] =&gt; gif
              [size] =&gt; 625
              [md5] =&gt; 71291239asskf9320234kasjd8239393
          )
  )
  </code></pre>
  
  <p>Old Report:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [file] =&gt; newhotfolder.gif
              [path] =&gt; images/newhotfolder.gif
              [type] =&gt; gif
              [size] =&gt; 1074
              [md5] =&gt; 8375h5910423aadbef67189c6b687ff51c
          )
  
      [1] =&gt; Array
          (
              [file] =&gt; image.gif
              [path] =&gt; images/attachtypes/image.gif
              [type] =&gt; gif
              [size] =&gt; 625
              [md5] =&gt; 7bbb66e191688a86b6f42a03bd412a6b
          )
  
      [2] =&gt; Array
          (
              [file] =&gt; footer.gif
              [path] =&gt; images/attachtypes/footer.gif
              [type] =&gt; gif
              [size] =&gt; 625
              [md5] =&gt; 1223819asndnasdn2213123nasd921
          )
  )
  </code></pre>
  
  <p>The function will have to be able to detect that the the md5 hash of "newhotfolder.gif" has changed, that the file "footer.gif" is deleted and that "header.gif" has been added. Perhaps return a third array like this?:</p>
  
  <p>Comparison:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [file] =&gt; newhotfolder.gif
              [path] =&gt; images/newhotfolder.gif
              [type] =&gt; gif
              [size] =&gt; 1074
              [md5] =&gt; 8375h5910423aadbef67189c6b687ff51c
              [status] =&gt; edited
          )
  
      [1] =&gt; Array
          (
              [file] =&gt; image.gif
              [path] =&gt; images/attachtypes/image.gif
              [type] =&gt; gif
              [size] =&gt; 625
              [md5] =&gt; 7bbb66e191688a86b6f42a03bd412a6b
              [status] =&gt; same
          )
  
      [2] =&gt; Array
          (
              [file] =&gt; footer.gif
              [path] =&gt; images/attachtypes/footer.gif
              [type] =&gt; gif
              [size] =&gt; 625
              [md5] =&gt; 1223819asndnasdn2213123nasd921
              [status] =&gt; deleted
          )
  
      [3] =&gt; Array
          (
              [file] =&gt; header.gif
              [path] =&gt; images/attachtypes/header.gif
              [type] =&gt; gif
              [size] =&gt; 625
              [md5] =&gt; 71291239asskf9320234kasjd8239393
              [status] =&gt; new
          )
  )
  </code></pre>