2016-11-16 2 views
0

내 Symfony2 프로젝트에서 KnpPaginatorBundle을 사용하고 있습니다. 당신이 currentPageNumber 여기 문자열입니다 볼 수 있듯이KnpPaginatorBundle은 currentPageNumber를 정수로 반환합니다.

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

: 나는 결과의 특정 페이지를 요청하고 매번는, 결과가 나에게 반환하는 것 같습니다. 이 속성의 유형을 정수로 변경하려면 어떻게해야합니까?

$intValue = (int) "123"; 

을 그리고이 경우를 보면 :

답변

0

당신은 PHP에 캐스팅 standarttype을 사용할 수있는 예제를 들어 (documentation)

당신은 이런 식으로 작업을 수행 할 수 있습니다

$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