# PHP Variable – int, boolean, null, double variable types with examples

### What is variable?

Just like in any programming language, PHP Variables are the way to store information in the middle of the PHP programs.

### Important things to know about variables

• Variables in PHP are declared/denoted by using a leading \$ sign. e.g.

\$variablename

• The most recent assignment to a variable is the value of that variable.
• The assignment operator used in variables is ‘=’ sign where a variable is on the left and expression to be at the right side.

e.g.

\$variablename = “variable value”;

• In PHP, the variables can be declared before assignment but it is not necessary.
• Variables are not intrinsic types i.e. a variable does not know if it will be used to store a number or string.
• Before assigning any value, the variables have default values.
• When necessary, PHP can automatically convert types from one to another.

### Types of variables

There is a total of 8 data types that are used to construct variables in PHP.

#### PHP Integers

PHP int is the whole numbers without a decimal point. An example of int variable is:

#### The Double type

The Double are the numbers with decimal point e.g. 1.234 or 50.1.

#### Boolean data type

The Boolean variables may be assigned only two possible values. Either true or false. The example of PHP Boolean variable is:

#### PHP NULL type

The Null type is a special variable type that has only one value i.e. Null

#### PHP Strings

Strings are the combination of characters e.g. ‘PHP supports string operations.’

The escape sequence in strings

You can use the following escape sequence within strings for respective results:

1. n means adding a new line.
2. r meant to be replaced by the carriage-return character.
3. t in a string means to replace by the tab character.
4. \$ is replaced by the dollar sign (\$).
5. means a single double-quote (“).
6. \ means to add a single backslash ().

#### Arrays

Arrays in PHP are names and the indexed collection of values. Please see the dedicated chapter for declaring and using Arrays in PHP.

#### Objects

Object variables store instances of classes. This can package another kind of values and functions specific to use a class.

#### Resources

These are the special type that holds references to the resources external to PHP like a database connection.

This chapter explained only first 5 types that are simple in nature. Arrays and Objects are the compound in nature that can package up other arbitrary values of arbitrary types. The later types will be explained in their respective chapters in this PHP tutorial.

### Naming conventions of variables

For choosing the name of your PHP variables, a few rules should be followed:

• The variable should start with a letter or an underscore “_”.
• The variable names can be combinations of a-z, A-Z, 0-9 or _ i.e. alpha-numeric characters, and underscores.
• If your variable is more than one word then it should be separated with an underscore e.g. \$first_second.
{"ft_lang_label":"__label__en","ft_lang_prob":0.78588957,"math_prob":0.8738446,"size":3371,"snap":"2019-51-2020-05","text_gpt3_token_len":814,"char_repetition_ratio":0.12800713,"word_repetition_ratio":0.014876033,"special_character_ratio":0.26016018,"punctuation_ratio":0.11836115,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95907885,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-19T03:34:26Z\",\"WARC-Record-ID\":\"<urn:uuid:e4371d0a-6ec6-47da-826b-5a28dd66ff81>\",\"Content-Length\":\"59938\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:18c3a8c2-579a-4739-837f-ed2f811e72d1>\",\"WARC-Concurrent-To\":\"<urn:uuid:28b22457-507b-448e-aa70-86d78f316be6>\",\"WARC-IP-Address\":\"195.123.240.172\",\"WARC-Target-URI\":\"https://www.tutorialscollection.com/faq/php-variables-variable-types-in-php/\",\"WARC-Payload-Digest\":\"sha1:DRNHHNVJNKSW5LQY7SHP35Q37EY7NXWS\",\"WARC-Block-Digest\":\"sha1:WYR77MIQG7OE7VIMKBC5SRYBIRHH42H3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250594101.10_warc_CC-MAIN-20200119010920-20200119034920-00110.warc.gz\"}"}