{"id":47,"date":"2023-05-06T02:51:57","date_gmt":"2023-05-06T02:51:57","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.com\/?p=47"},"modified":"2023-05-06T02:51:57","modified_gmt":"2023-05-06T02:51:57","slug":"what-is-variable-in-php-and-its-types","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2023\/05\/06\/what-is-variable-in-php-and-its-types\/","title":{"rendered":"What is variable in PHP and its types?"},"content":{"rendered":"\n<p>In PHP, a variable is declared using a $ sign followed by the variable name. Here, some important points to know about variables:<\/p>\n\n\n\n<ul>\n<li>As PHP is a loosely typed language, we do not need to declare the data types of the variables. It automatically analyses the values and makes conversions to its correct data type.<\/li>\n\n\n\n<li>After declaring a variable, it can be reused throughout the code.<\/li>\n\n\n\n<li>Assignment Operator (=) is used to assign the value to a variable.<\/li>\n<\/ul>\n\n\n\n<p>Syntax of declaring a variable in PHP is given below:<\/p>\n\n\n\n<p>$variablename = value;<\/p>\n\n\n\n<p><strong>Rules for declaring PHP variable:<\/strong><\/p>\n\n\n\n<ul>\n<li>A variable must start with a dollar ($) sign, followed by the variable name.<\/li>\n\n\n\n<li>It can only contain alpha-numeric characters and underscore (A-z, 0-9, _).<\/li>\n\n\n\n<li>A variable name must start with a letter or underscore (_) character.<\/li>\n\n\n\n<li>A PHP variable name cannot contain spaces.<\/li>\n\n\n\n<li>One thing to be kept in mind is that the variable name cannot start with a number or special symbols.<\/li>\n\n\n\n<li>PHP variables are case-sensitive, so $name and $NAME both are treated as different variables.<\/li>\n<\/ul>\n\n\n\n<p>PHP has a total of eight data types which we use to construct our variables \u2212<\/p>\n\n\n\n<ul>\n<li>Integers \u2212 are whole numbers, without a decimal point, like 4195.<\/li>\n\n\n\n<li>Doubles \u2212 are floating-point numbers, like 3.14159 or 49.1.<\/li>\n\n\n\n<li>Booleans \u2212 have only two possible values either true or false.<\/li>\n\n\n\n<li>NULL \u2212 is a special type that only has one value: NULL.<\/li>\n\n\n\n<li>Strings \u2212 are sequences of characters, like &#8216;PHP supports string operations.&#8217;<\/li>\n\n\n\n<li>Arrays \u2212 are named and indexed collections of other values.<\/li>\n\n\n\n<li>Objects \u2212 are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.<\/li>\n\n\n\n<li>Resources \u2212 are special variables that hold references to resources external to PHP (such as database connections).<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In PHP, a variable is declared using a $ sign followed by the variable name&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/47"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":1,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/47\/revisions"}],"predecessor-version":[{"id":48,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/47\/revisions\/48"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}