我在我的Symfony2项目中使用了KnpPaginatorBundle。每次我请求某个页面的结果时,结果都会返回给我,如下所示:
{
"currentPageNumber": "2",
"numItemsPerPage": 5,
"items": [ ...
]
}正如你所看到的,currentPageNumber在这里是字符串。如何将此属性的类型更改为整数?
发布于 2016-11-16 17:07:00
你可以在php (documentation)中使用标准类型转换。
对于示例,您可以这样做:
$intValue = (int) "123";看看这个例子:
$stringValue = "123";
echo gettype($stringValue); // will be 'string' here
$intFromStringValue = (int) $stringValue;
echo gettype($intFromStringValue); // will be 'integer' here
// but be aware of this
echo (int) "Some words"; // will be integer but value will be 0, because type casting cannot get the number from string
echo (int) "200 and some words"; // integer 200
echo (int) "Some words and 300"; // integer 0https://stackoverflow.com/questions/40627853
复制相似问题