简体   繁体   中英

php for is not working if i pass the values through variable

i am parsing a XML data with simplexml_load_file() function and when i display the data using for loop its display correctly from the number i mention to the limit

<?php
for($i=10; $i<=20; $i++){
{
 $offer->name;
}
?>

but when i declare the values through variable it does not work.

<?php
$result_start = $_REQUEST['start'];
$result_limit = $_REQUEST['limit'];


for($i=$result_start; $i<=$result_limit; $i++){
{
 $offer->name;
}
?>

one more strange thing is happening here is that the loop is repeating 2 times more. like if i mention the loop from 10 to 20 so it is showing me the values from 10 to 22.

It seems to me the problem would most easily be solved by casting the user input to integers:

$result_start = (int) $_REQUEST['start'];
$result_limit = (int) $_REQUEST['limit'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM