You are here

function adserve_select_reindex in Advertisement 6

Same name and namespace in other branches
  1. 5 adserve.inc \adserve_select_reindex()

Remove one or more ids from array. TODO: Optimize. Perhaps something like array_flip, unset, array_flip.

Parameters

$ids An array of ID's, ie array(5, 8, 9, 11).:

$remove An ID or an array of ID's to be removed from $ids.:

1 call to adserve_select_reindex()
adserve_select_ad in ./adserve.inc
Simple default function to randomly select an ad. Provides a hook to allow the definition of external display methods.

File

./adserve.inc, line 487
Configuration.

Code

function adserve_select_reindex($ids, $remove) {
  $new = array();

  // Walk through array of IDs and decide what to keep.
  foreach ($ids as $id) {

    // If $remove is an array, walk through array to decide fate of ID.
    if (is_array($remove)) {
      $keep = TRUE;
      foreach ($remove as $rem) {

        // Loop until we find one that matches or reach end of array.
        if ($id == $rem) {
          $keep = FALSE;
          break;
        }
      }
      if ($keep) {
        $new[] = $id;
      }
    }
    else {
      if ($id != $remove) {
        $new[] = $id;
      }
    }
  }
  return $new;
}