Re: [PHP] Type of a variable in PHP

[email protected] (Norah Jones)
Newsgroups php.general
Message-ID <CAHLRmfVSB--9_83CudmnaGjxHDkFW395BO_OKNaq9-rTCrDpTw@mail.gmail.com>
Try this

function get_type($var)
{
    if(is_object($var))
        return get_class($var);
    if(is_null($var))
        return 'null';
    if(is_string($var))
        return 'string';
    if(is_array($var))
        return 'array';
    if(is_int($var))
        return 'integer';
    if(is_bool($var))
        return 'boolean';
    if(is_float($var))
        return 'float';
    if(is_resource($var))
        return 'resource';
    //throw new NotImplementedException();
    return 'unknown';
}



On Fri, Mar 15, 2013 at 3:28 PM, Karim Geiger <[email protected]> wrote:

> Hi,
>
> On Fri, 2013-03-15 at 09:55 +0000, Kevin Peterson wrote:
> > Have two questions -
> > 1. How to find type of a variable in PHP.
> > 2. How to find the type of an array in PHP.
> >
> > Please help.
> >
>
> Use this:
> http://php.net/manual/en/function.gettype.php
>
> Regards
>
> Karim
>
> --
> Karim Geiger
>
> B1 Systems GmbH
> Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
> GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.