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;


PHP

Avatar of undefined
Last Comment
darren-w-

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
darren-w-

function extractNum($aNumber,$num){
$temp = str_split ($aNumber);

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

}
return $rtn;
}

Open in new window

darren-w-

use substr :), assume the logic is similar the in the source
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy