首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >KnpPaginatorBundle以整数形式返回currentPageNumber

KnpPaginatorBundle以整数形式返回currentPageNumber
EN

Stack Overflow用户
提问于 2016-11-16 17:04:02
回答 1查看 37关注 0票数 0

我在我的Symfony2项目中使用了KnpPaginatorBundle。每次我请求某个页面的结果时,结果都会返回给我,如下所示:

代码语言:javascript
复制
{
  "currentPageNumber": "2",
  "numItemsPerPage": 5,
  "items": [ ...
   ]
}

正如你所看到的,currentPageNumber在这里是字符串。如何将此属性的类型更改为整数?

EN

回答 1

Stack Overflow用户

发布于 2016-11-16 17:07:00

你可以在php (documentation)中使用标准类型转换。

对于示例,您可以这样做:

代码语言:javascript
复制
$intValue = (int) "123";

看看这个例子:

代码语言:javascript
复制
$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 0
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40627853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档