Reputation: 239
I have a Foreach where I have two variables ($num1 and $num2) as string. I'd like to covert them as number (integer should be ok).
This is my code:
...
foreach ($titles as $match) {
list($num1, $num2) = explode(':', $results[$c++]->innertext); // <- explode
echo "<tr><td class='rtitle'>".
"<td class='last-cell'>".$match_dates[$c]->innertext . "</td> " .
//"<td class='first-cell tl'>".$match->innertext."</td> " .
" - ".$match->innertext." ".$num1.':'.$num2 . " " .
"<td class='odds'>".$best_bets[$b++]->attr['data-odd'] . ";" .
"".$odds[$b++]->attr['data-odd'] . ";" .
"".$odds[$b++]->attr['data-odd'] . "</td>" .
"</td></tr><br/>";
}
...
Thanks!
EDIT
Thanks for your answer. I am going to explain and maybe you could help me: I have a a problem with best_bets
value, because it's not alway before odds variable, so I was thinking to use "if statement", where I can fix some rules: when $num1
is > $num2
, I will show an echo order; when $num1
is = $num2
another echos order and. at least, $num1
is < $num2
another echos order. But to do this, I need to convert $num1 and $num2 to do it. I hope to be clear. Thank you for your helping
Upvotes: 0
Views: 42
Reputation: 459
You could cast them to an int:
$num1 = (int) $num1;
Or use the intval function:
$num1 = intval($num1);
Hope this helps.
Upvotes: 1