fishingboy / type-converter
convert php value type for api output
1.0.2
2020-03-11 03:28 UTC
Requires
- ext-json: *
This package is auto-updated.
Last update: 2025-04-24 01:31:25 UTC
README
Language
Introduce
Because when the app (Android and iOS) is connected to the api written in php, there are often confusing or flashbacks in the connection because the php data type is not fixed, so I hope to do a type conversion before outputting the api.
Installation
composer require fishingboy/type-converter
Usage
Import class
use fishingboy\type_converter\Type_Converter;
convert data before api output
$converter = new Type_Converter( '{ "users":[ { "name":"str", "height":"float", "age":"int", "adult":"bool" } ] }'); $response = $converter->convert([ "users" => [ ["name" => "leo", "height" => 173.5, "age" => "12", "adult" => false], ["name" => "rain"], ["name" => 819040, "age" => 14], ] ]);
output your api
echo json_encode($response);
type
- int
- float
- bool
- str