Source for file modifier.unique.php

Documentation is available at modifier.unique.php

  1. <?php
  2. /**
  3.  *  smarty modifier:unique()
  4.  *
  5.  *  unique()関数のwrapper
  6.  *
  7.  *  sample:
  8.  *  <code>
  9.  *  $smarty->assign("array1", array("a", "a", "b", "a", "b", "c"));
  10.  *  $smarty->assign("array2", array(
  11.  *      array("foo" => 1, "bar" => 4),
  12.  *      array("foo" => 1, "bar" => 4),
  13.  *      array("foo" => 1, "bar" => 4),
  14.  *      array("foo" => 2, "bar" => 5),
  15.  *      array("foo" => 3, "bar" => 6),
  16.  *      array("foo" => 2, "bar" => 5),
  17.  *  ));
  18.  *
  19.  *  {$array1|@unique|@join:''}
  20.  *  {$array2|@unique:"foo"|@join:''}
  21.  *  </code>
  22.  *  <code>
  23.  *  abc
  24.  *  123
  25.  *  </code>
  26.  *
  27.  *  @param  array   $array  処理対象となる配列
  28.  *  @param  key     $key    処理対象となるキー(nullなら配列要素)
  29.  *  @return array   再構成された配列
  30.  */
  31. function smarty_modifier_unique($array$key null)
  32. {
  33.     if (is_array($array== false{
  34.         return $array;
  35.     }
  36.     if ($key != null{
  37.         $tmp array();
  38.         foreach ($array as $v{
  39.             if (isset($v[$key]== false{
  40.                 continue;
  41.             }
  42.             $tmp[$v[$key];
  43.         }
  44.         return array_unique($tmp);
  45.     else {
  46.         return array_unique($array);
  47.     }
  48. }

Documentation generated on Fri, 11 Nov 2011 04:01:17 +0900 by phpDocumentor 1.4.3