Monday 28 November 2011

Variable Function


Ø       gettype

  • Return the type of php variable.
  • Possible return value are Boolean, integer, double, string, array, null, object resources, user function.


            Syntax

                        String gettype(mixed $var)

Example

<?php
          $str ="Hello World";
          echo gettype($str);
          ?>

Output  

                   String

Ø       settype

  • Set the type of variable.


            Syntax

                        bool settype(mixed $var, string type)

Parameter
Description
var
The variable being converted.
Type
Possible values of type are Boolean, integer, float, string, array, object, null.

Example

<?php
          $str ="Hello World";
          settype($str,"string")."<br/>";
          echo gettype($str);
          ?>
Output  

                   string

Ø       isset

  • Determine whether a variable is set.
  • Returns true if variable exits, false otherwise.

Syntax

                        bool isset(mixed $var[,mixed $var…] )

Example

<?php
          $str ="Hello World";
          if(isset($str))
          {
                   echo "variable is set.";
          }
          else
          {
                   echo "variable is not set.";
          }
          ?>

Output  

                   variable is set.

Ø       unset

  • unset a given variable.
  • unset() destroy the specified variables.

Syntax

                        void unset(mixed $var[,mixed $var…] )

Example

<?php
          $str ="Hello World";
          echo $str."<br/>";
          unset($str);
          echo "variable unset";
          ?>

Output  

                   Hello World
                   variable unset.

Ø       strval

  • This function is used to convert any data type value of PHP into string value and will return string value.

Syntax

                        string strval(mixed $var)

Example

<?php
          $str ="Hello World";
          echo strval($str);
          ?>

Output  

                   Hello World

Ø       floatval

  • This function is used to convert the mixed data type into the float data type.

Syntax

                        float floatval(mixed $var)

Example

<?php
          $str ="0.5";
          $num = floatval($str);
          echo gettype($num);
          ?>

Output  

                   Double

Ø       intval

  • This function is used to convert the mixed data type into the integer data type.

Syntax

                        Integer intval(mixed $var)

Example

<?php
          $str ="5";
          $num = intval($str);
          echo gettype($num);
          ?>

Output  

                   Integer

Ø       print_r

  • This function will display the array in the array in the format as it is declare in the code. The return type is void.

Syntax

                        void print_r(array variable)

Example

<?php
          $str ="5";
          $num = intval($str);
          echo gettype($num);
          ?>

Output  

                  Array ( [0] => 1 [1] => 2 )

Posted By : Hemangi Zala

No comments:

Post a Comment