Like the title says. I really can't explain what kind of function I should be using to get this variable. Can anyone help?
$var = 100; echo substr( $var, 0, 1); //result = 1 $var = 1300; echo substr( $var, 0, 2); //result = 13
although this may not be the exact solution it's a step in the right direction...substr can be read about in the php manual here
You can use strlen to count how many numbers there are, then use substr accordingly.
if(strlen($var)=="3"){//if it's by the 100's echo substr( $var, 0, 1); } else { echo substr($var, 0, 2);//if it's by the 1000's }
<?php $intNumber = 100; // or 1300, 1475, ................. echo floor($intNumber / 100); ?>
Thanks you for the different ways to approach this.