luya\helpers\ArrayHelper::typeCast PHP Méthode

typeCast() public static méthode

This method is often used to convert corect json respons arrays
public static typeCast ( array $array ) : array
$array array The array which should be type casted
Résultat array An array with type casted values
    public static function typeCast($array)
    {
        $return = [];
        foreach ($array as $k => $v) {
            if (is_numeric($v)) {
                if (is_float($v)) {
                    $return[$k] = (double) $v;
                } else {
                    $return[$k] = (int) $v;
                }
            } elseif (is_array($v)) {
                $return[$k] = self::typeCast($v);
            } else {
                $return[$k] = $v;
            }
        }
        return $return;
    }

Usage Example

 public function getData()
 {
     $cleandata = [];
     foreach ($this->_data as $key => $value) {
         $cleandata[] = ['value' => $key, 'label' => $value];
     }
     return ArrayHelper::typeCast($cleandata);
 }
All Usage Examples Of luya\helpers\ArrayHelper::typeCast