Issue
I have one function called conversionData() which takes the input from the request and converts based on the type of input .
Public static function conversationData (Request $request){
$value=$request->type;
if(is_float($value)){
//return some code
}
if(is_string($value)){
// Return code
}
else{
// If it's integer
return $value;
}
}
if i give in url as {url}&type=33.34 it should exceute is_float condition but it executes is_string condition.how to execute correctly please help me
Solution
you can check for float then integer then string, cheking $value for float using this way:
$floatVal = floatval($value);
// If the parsing succeeded and the value is not equivalent to an int
if($floatVal && intval($floatVal) != $floatVal)
{
// $num is a float
//return some code
}
it's not a float, then continue cheking:
if(is_integer($value)){
//return some code
}
if(is_string($value)){
// Return code
}
else{
return $value;
}
Answered By - OMR Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.