0

So I outputed a result from {{blogs.totalPage}}.This {{blogs.totalPage}} has a value of 5. Then this value, I added it to my while loop. But the while loop is not working and the ouput is 0 because the outputed value 5 is String not Int.

<?php
$cnt = 0;

$pageTotal = "'{{blogs.totalPage}}'";

while($cnt<=$pageTotal){
echo "Number: ".$cnt
$cnt++;
}

Then I tried adding (int)

<?php
$cnt = 0;

$pageTotal = (int)"'{{blogs.totalPage}}'";
while($cnt<=$pageTotal){
echo "Number: ".$cnt
$cnt++;
}

Can you help me to convert this String into Int to make my while loop working? Thanks

Let me add, the reason why I know it is string and has an output of 5, I tried to var_dump($pageTotal) and the output is string(21) "'5'"

ICG DEVS
  • 195
  • 3
  • 15
  • Possible duplicate of [How do I convert a string to a number in PHP?](https://stackoverflow.com/questions/8529656/how-do-i-convert-a-string-to-a-number-in-php) – Will Da Silva May 28 '19 at 13:23
  • I don't see from your question how `"'{{blogs.totalPage}}'"` gets converted to a value of "5". Are you sure $pageTotal is actually "5" or are you assuming that it should be? – dweipert May 28 '19 at 13:24
  • @DRogueRonin It is, I var dump it, the output is `string(21) "'5'"` – ICG DEVS May 28 '19 at 13:32
  • @WillDaSilva This is not a Possible duplicate, this is VueJS + PHP, and as you can see I already tried (int). Please read the question properly before marking it as duplicate. – ICG DEVS May 28 '19 at 13:33
  • @ICGDEVS Have you tried the other methods in the answer here: https://stackoverflow.com/a/8529678/5946921 – Will Da Silva May 28 '19 at 13:39
  • Did you try just removing the single quotes around `{{blogs.totalPage}}` ? – dweipert May 28 '19 at 13:39
  • @DRogueRonin it will no longer works if I removed that, the 5 will become 0. – ICG DEVS May 28 '19 at 13:44
  • @WillDaSilva, I tried the link you gave, the intval(), but sadly, it didnt work also. the output became 0 which is should be 5. – ICG DEVS May 28 '19 at 13:49
  • Are you using Vue and PHP in the same page (file)? If so, I'm curious as to why? – Alex Mulchinock May 28 '19 at 14:45

0 Answers0