PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 7, 2022

[FIXED] How to write multiple conditions with functions in laravel?

 August 07, 2022     decimal, laravel, php     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing