0

Symfony2 プロジェクトで KnpPaginatorBundle を使用しています。結果の特定のページをリクエストするたびに、次のような結果が返されます。

{
  "currentPageNumber": "2",
  "numItemsPerPage": 5,
  "items": [ ...
   ]
}

ご覧のとおり、currentPageNumberここに文字列があります。このプロパティのタイプを整数に変更するにはどうすればよいですか?

4

1 に答える 1

0

php で standardtype キャストを使用できます (ドキュメント)

サンプルの場合、次のようにできます。

$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 0
于 2016-11-16T09:06:59.897 に答える