You are here

function drupalforfirebug_array_compare_code in Drupal For Firebug 5

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

Specialized Array Data Retrival Function

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

File

./drupalforfirebug.module, line 343

Code

function drupalforfirebug_array_compare_code($a, $b, $c = 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 (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
      $c['#firebug_style'][$akeys[$x]] = 'REMOVED';
    }

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

      // is b a valid array
      $c[$akeys[$x]] = drupalforfirebug_array_compare_code($a[$akeys[$x]], $b[$akeys[$x]], $c[$akeys[$x]]);
    }
    else {
      if (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
        $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
    if (is_array($b[$bkeys[$x]])) {

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