yii\helpers\BaseArrayHelper::htmlEncode PHP Method

htmlEncode() public static method

Only array values will be encoded by default. If a value is an array, this method will also encode it recursively. Only string values will be encoded.
See also: http://www.php.net/manual/en/function.htmlspecialchars.php
public static htmlEncode ( array $data, boolean $valuesOnly = true, string $charset = null ) : array
$data array data to be encoded
$valuesOnly boolean whether to encode array values only. If false, both the array keys and array values will be encoded.
$charset string the charset that the data is using. If not set, [[\yii\base\Application::charset]] will be used.
return array the encoded data
    public static function htmlEncode($data, $valuesOnly = true, $charset = null)
    {
        if ($charset === null) {
            $charset = Yii::$app ? Yii::$app->charset : 'UTF-8';
        }
        $d = [];
        foreach ($data as $key => $value) {
            if (!$valuesOnly && is_string($key)) {
                $key = htmlspecialchars($key, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
            }
            if (is_string($value)) {
                $d[$key] = htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
            } elseif (is_array($value)) {
                $d[$key] = static::htmlEncode($value, $valuesOnly, $charset);
            } else {
                $d[$key] = $value;
            }
        }
        return $d;
    }