1
0
mirror of https://github.com/restoreddev/phpapprentice.git synced 2025-07-30 19:40:43 +02:00

Created initial site setup with hugo

This commit is contained in:
Andrew Davis
2019-07-12 19:21:18 -05:00
parent 77a0d2616b
commit e09557cf2c
80 changed files with 732 additions and 10488 deletions

43
content/02-variables.md Normal file
View File

@@ -0,0 +1,43 @@
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';
```