Posts

Showing posts with the label Data types in PHP

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   fun...