https://github.com/maxlcoder/data-type
https://github.com/maxlcoder/data-type
data-type
Last synced: 29 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/maxlcoder/data-type
- Owner: maxlcoder
- Created: 2017-10-18T08:11:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-19T02:19:56.000Z (over 8 years ago)
- Last Synced: 2024-04-17T19:04:43.608Z (almost 2 years ago)
- Topics: data-type
- Language: PHP
- Size: 1000 Bytes
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### 数组或对象属性类型转换
#### 配置
> 需要转换的属性与类型
>
> 支持类型有
>
> - "boolean" or "bool"
> - "integer" or "int"
> - "float" or "double"
> - "string"
> - "array"
> - "object"
> - "null"
#### 示例
```php
// 举例
$configs = [
'username' => 'string',
'age' => 'int',
];
$datas = [
'username' => 'Lily', // string
'age' => '12', // string
];
var_dump($datas);
/*
array(2) {
["username"]=>
string(4) "Lily"
["age"]=>
string(2) "12"
}
*/
$app = new DataType($configs);
$results = $app->convert($datas);
var_dump($results);
/*
array(2) {
["username"]=>
string(4) "Lily"
["age"]=>
int(12)
}
*/
```