Link to home
Start Free TrialLog in
Avatar of savsofts
savsofts

asked on

PHP function to select first two values of variable

Hello,

i need php function to select first two values of variable.

eg.
 $val=3456;
or  
$val=34567;

then it will pick only first two values
$val=34;


ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
function extractNum($aNumber,$num){
$temp = str_split ($aNumber);

for($i=0;$i<$num;$i++){
$rtn.=$temp[$i];

}
return $rtn;
}

Open in new window

use substr :), assume the logic is similar the in the source