You are here

function drupalforfirebug_array_compare_code in Drupal For Firebug 7.2

Same name and namespace in other branches
  1. 5 drupalforfirebug.module \drupalforfirebug_array_compare_code()
  2. 6 drupalforfirebug.module \drupalforfirebug_array_compare_code()
  3. 7 drupalforfirebug.module \drupalforfirebug_array_compare_code()

Specialized Array Data Comparision Code

1 call to drupalforfirebug_array_compare_code()
drupalforfirebug_array_compare in ./drupalforfirebug.module
Generalized Array Comparision Function

File

./drupalforfirebug.module, line 503

Code

function drupalforfirebug_array_compare_code($a, $b, $c = array(), $history = array()) {

  // Create the Compared Data Object
  $maxcount = count($a) > count($b) ? count($a) : count($b);
  $akeys = is_array($a) ? array_keys($a) : array();
  $bkeys = is_array($b) ? array_keys($b) : array();
  for ($x = 0; $x < $maxcount; $x++) {

    // Set the Proper Styling
    if (isset($akeys[$x]) && array_key_exists($akeys[$x], array_flip($bkeys))) {

      // is it in B array?
      if ($a[$akeys[$x]] === $b[$akeys[$x]]) {
        $c['#firebug_style'][$akeys[$x]] = 'SAME';
      }
      else {
        $c['#firebug_style'][$akeys[$x]] = 'DIFFERENT';
      }
    }
    else {

      // not in B array, must be removed
      if (isset($akeys[$x])) {
        $c['#firebug_style'][$akeys[$x]] = 'REMOVED';
      }
    }

    // Set the Proper Element
    if (isset($akeys[$x]) && is_array($a[$akeys[$x]]) && $bkeys) {

      // is b a valid array
      if (isset($c[$akeys[$x]])) {
        $aval =& $a[$akeys[$x]];
        $bval =& $b[$akeys[$x]];
        $cval =& $c[$akeys[$x]];
        $c[$akeys[$x]] = drupalforfirebug_array_compare_code($aval, $bval, $cval);
      }
      else {
        $aval =& $a[$akeys[$x]];
        $bval =& $b[$akeys[$x]];
        $c[$akeys[$x]] = drupalforfirebug_array_compare_code($aval, $bval, array());
      }
    }
    else {
      if (isset($akeys[$x]) && array_key_exists($akeys[$x], array_flip($bkeys))) {

        // is it in B array?
        if ($a[$akeys[$x]] === $b[$akeys[$x]]) {
          $c[$akeys[$x]] = $a[$akeys[$x]];
        }
        else {
          $c[$akeys[$x]] = $b[$akeys[$x]];
        }
      }
      else {

        // not in B array, must be removed
        if (isset($akeys[$x])) {
          $c[$akeys[$x]] = $a[$akeys[$x]];
        }
      }
    }
    if (isset($bkeys[$x]) && isset($b[$bkeys[$x]])) {

      // does b have a valid argument
      // Set the Proper Styling
      if (array_key_exists($bkeys[$x], array_flip($akeys))) {

        // is it in A array?
        // exists in the A array, already processed
      }
      else {
        $c[$bkeys[$x]] = $b[$bkeys[$x]];
        $c['#firebug_style'][$bkeys[$x]] = 'ADDED';
      }

      // Set the Proper Element
      $aval =& $a[$bkeys[$x]];
      $bval =& $b[$bkeys[$x]];
      $cval =& $c[$bkeys[$x]];
      if (isset($bval) && is_array($bval) && isset($aval) && isset($cval)) {

        // is b a valid array
        $c[$bkeys[$x]] = drupalforfirebug_array_compare_code($aval, $bval, $cval);
      }
    }
  }
  return $c;
}