fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@ -0,0 +1,111 @@
---
title: PHP Data Types
---
# Data Types
Variables can store data of different types such as:
* String ("Hello")
* Integer (5)
* Float (also called double) (1.0)
* Boolean ( 1 or 0 )
* Array ( array("I", "am", "an", "array") )
* Object
* NULL
* Resource
## String
A string is a sequence of characters. It can be any text inside quotes (single or double):
#### Example
```php
$x = "Hello!";
$y = 'Hello!';
```
## Integer
An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.
Rules for integers:
* An integer must have at least one digit
* An integer must not have a decimal point
* An integer can be either positive or negative
* Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based - prefixed with 0x) or octal (8-based - prefixed with 0)
#### Example
```php
$x = 5;
```
## Float
A float (floating point number) is a number with a decimal point or a number in exponential form.
#### Example
```php
$x = 5.01;
```
## Boolean
A Boolean represents two possible states: TRUE or FALSE. Booleans are often used in conditional testing.
```php
$x = true;
$y = false;
```
## Array
An array stores multiple values in one single variable.
```php
$colours = array("Blue","Purple","Pink");
```
## NULL Value
Null is a special data type which can have only one value: NULL.
A variable of data type NULL is a variable that has no value assigned to it.
Variables can also be emptied by setting the value to NULL.
**Note:** If a variable is created without a value, it is automatically assigned a value of NULL.
```php
<?php
$x = "Hello world!";
$x = null;
?>
```
Output:
NULL
## Object
An object is a data type which stores data and information on how to process that data.
In PHP, an object must be explicitly declared.
First we must declare a class of object. A class is a structure that can contain properties and methods.
**Example:**
```php
<?php
class Car {
function Car() {
$this->model = "VW";
}
}
// create an object
$herbie = new Car();
// show object properties
echo $herbie->model;
?>
```

View File

@ -0,0 +1,71 @@
---
title: Variables
---
## Variables
# Creating (Declaring) PHP Variables
Variables are "containers" for storing information.
**Syntax:**
```php
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
```
After the execution of the statements above, the variable $txt will hold the value Hello world!, the variable $x will hold the value 5, and the variable $y will hold the value 10.5.
##### Note: When you assign a text value to a variable, put quotes around the value.
##### Note: Unlike other programming languages, PHP has no command for declaring a variable. It is created the moment you first assign a value to it.
# Rules for PHP variables:
* A variable starts with the $ sign, followed by the name of the variable
* A variable name must start with a letter or the underscore character
* A variable name cannot start with a number
* A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
* Variable names are case-sensitive ($age and $AGE are two different variables)
# Output Variables
The PHP echo statement is often used to output data to the screen.
The following example will show how to output text and a variable:
````php
<?php
$txt = "github.com";
echo "I love $txt!";
?>
````
The following example will produce the same output as the example above:
````php
<?php
$txt = "github.com";
echo "I love " . $txt . "!";
?>
````
The following example will output the sum of two variables:
````php
<?php
$x = 5;
$y = 4;
echo $x + $y;
?>
````
# PHP is a Loosely Typed Language
In the example above, notice that we did not have to tell PHP which data type the variable is.
PHP automatically converts the variable to the correct data type, depending on its value.
In other languages such as C, C++, and Java, the programmer must declare the name and type of the variable before using it.
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->