1
0
mirror of https://github.com/restoreddev/phpapprentice.git synced 2025-10-24 11:26:06 +02:00

Converted chapters to markdown and changed pages to vertical layout

This commit is contained in:
Andrew Davis
2019-01-02 20:12:35 -06:00
parent 0c17549268
commit cbd3c539bb
56 changed files with 1305 additions and 1060 deletions

44
chapters/variables.md Normal file
View File

@@ -0,0 +1,44 @@
The variable is the basic building block of any programming language.
In PHP, all variables start with a dollar sign.
```php
<?php
$greeting;
```
To set data in a variable, you put an equals sign after it and some data.
```php
$greeting = 'Hello World!';
```
Once you create a variable, you can use it again in other commands and functions.
```php
echo $greeting;
```
After the dollar sign, a PHP variable must have an alphabetic character or underscore. Also, variables are case sensitive.
```php
$_var = 'I am a variable with an underscore!';
$Var = 'I am a variable with a capital letter!';
$var = 'I am a new variable';
```
Variables can hold many different types of data, but there are four simple ones you can try now.
An int is a number without a decimal place.
A float is a number with a decimal place.
A boolean can be two values: true or false.
Last, there is a string: a collection of characters.
```php
$int = 1;
$float = 100.10;
$bool = true;
$string = 'I am a string';
```
In other programming languages, you have to write what type of data the variable will contain.
PHP keeps it simple by allowing you to put any type of data in a variable, including already used variables.
```php
$number = 1;
$number = 'one';
```