Posts

Showing posts from April, 2022

Numbers in PHP

 PHP Integers Check if variable type is Integer <?php $x =  5985 ; var_dump(is_int($x)); $x =  59.85 ; var_dump(is_int($x)); ?> PHP Floats Check if variable type is Floats <?php $x =  10.365 ; var_dump(is_float($x)); ?> PHP Infinity Check if value in infinite or finite <?php $x =  1.9e411 ; var_dump($x); ?> PHP NAN Check if invalid calculation it return NAN <?php $x = acos( 8 ); var_dump($x); ?> PHP Numerical String <?php $x =  5985 ; var_dump(is_numeric($x)); $x =  "5985" ; var_dump(is_numeric($x)); $x =  "59.85"  +  100 ; var_dump(is_numeric($x)); $x =  "Hello" ; var_dump(is_numeric($x)); ?> Thanks for Reading. I hope it helps. Want to donate. Donate me Here

String In PHP

 There are following string functions in PHP: strlen() - in return the length of string. <?php echo  strlen( "Learn PHP by RK" );  // outputs 15 ?> str_word_count() - Count Words in a String <?php echo  str_word_count( "Learn PHP by RK" );  // outputs 4 ?> strrev() - Reverse a String <?php echo  strrev( "Hello world!" );  // outputs !dlrow olleH ?> strpos() - Search For a Text Within a String <?php echo  strpos( "Hello world!" ,  "world" );  // outputs 6 ?> str_replace() - Replace Text Within a String <?php echo  str_replace( "world" ,  "Dolly" ,  "Hello world!" );  // outputs Hello Dolly! ?> Thanks for reading. I hope It helps. Donate Me

Data Types in PHP

  PHP supports the following data types: String Integer Float (floating point numbers - also called double) Boolean Array Object NULL Resource There are some examples of data types in PHP, you can use it understand the concept: String <?php $x =  "Learn PHP By RK" ; $y =  'Learn Wordpress By RK' ; echo  $x; echo   "<br>" ; echo  $y; ?> Integer <?php $x =  9685 ; var_dump($x); ?> FLOAT <?php $x =  18.635 ; var_dump($x); ?> Boolean $x = true; $y = false; Array <?php $cars =  array ( "Iron Man" , "Hulk" , "Thor" ); var_dump($cars); ?> Object In the following example car in Class having properties color and model. <?php class  Car {    public  $color;    public  $model;    public   function  __construct($color, $model) {      $this->color = $color;     $this->model = $model;    }    public   function  message() {      return   "My car is a "  . $this->color .  " "  . $thi