LoginSignup
5
6

More than 5 years have passed since last update.

コールバック関数を使った再帰処理の例

Last updated at Posted at 2012-12-26
文字エンコーディングがUTF-8かの検証行う場合
function filter_encoding($val, $encording='UTF-8'){
    // 引数が配列の場合
    if (is_array($val)){
        // コールバック関数として再帰処理
        array_map('filter_encoding', $val);
    }

    // 検証
    if (mb_check_encoding($val, $encording){
        return $val;
    } else {
        // エラーの場合はログを取るなどの処理を記述
    }
}

別の関数でする場合は、mb_check_encoding()周辺をよしなにしてやってください。

5
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6