Skip to content

Commit

Permalink
feat: output and refactor variabled
Browse files Browse the repository at this point in the history
  • Loading branch information
codewithhridoy committed Mar 29, 2024
1 parent f5e7fdd commit 796029d
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 22 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/php-basics-to-advanced.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions 02_output.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php // This is a php tag. If there is no html or other content below the php, we don't need to close the php tag.

/* ------- Outputting Content ------- */

// Echo - Output strings, numbers, html, etc
echo 'Hello';
echo '<br/>';

echo 123;
echo '<br/>';

echo '<h1>Hello</h1>';

// print - Similar to echo, but a bit slower
print 'Hello';
echo '<br/>';

// print_r - Gives a bit more info. Can be used to print arrays
print_r('Hello');
echo '<br/>';

print_r([1, 2, 3]);
echo '<br/>';

// var_dump - Even more info like data type and length
var_dump('Hello');
echo '<br/>';

var_dump([1, 2, 3]);
echo '<br/>';

// Escaping characters with a backslash
echo 'You can\'t do that.';

$name = 'Ahmed';

// If there is more content after the PHP, such as this file, you do need the ending tag. Otherwise you do not.
?>

<!-- You can output any HTML that you want within a .php file -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My PHP Website</title>
</head>
<body>
<!-- You can output PHP including variables, etc -->
<h1>Hello <?php echo $name; ?></h1>
<!-- You may only drop the semi-colon after a statement when the statement is followed immediately by a closing PHP tag ?>. -->
<h1>Hello <?= $name ?></h1>
</body>
</html>
10 changes: 5 additions & 5 deletions 02_data_types.php → 03_data_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
$integer = 1; // int(1)
$float = 99.99; // float(99.99)
$boolean = true; //bool(true)
$even_numbers=[2,4,6,8];
$obj = (object) ['key' => 'value'];
$even_numbers=[2,4,6,8];
$object = (object) ['key' => 'value'];
$null = NULL; // NULL
$resource = fopen("example.txt", "r");
// $resource = fopen("example.txt", "r");

var_dump($null, $string, $integer, $float, $boolean, $even_numbers, $obj, $resource);
var_dump($null, $string, $integer, $float, $boolean, $even_numbers, $object);


/**
Expand All @@ -40,4 +40,4 @@
["key"]=>
string(5) "value"
}
*/
*/
17 changes: 0 additions & 17 deletions 03_variables.php

This file was deleted.

50 changes: 50 additions & 0 deletions 04_variables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* 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)
*/

$name = 'Ahmed'; // String // Can be single or double quotes
$age = 28; // Integer
$has_kids = true; // Boolean
$number_of_kids = 1; // Boolean
$cash_on_hand = 1_00_000.55; //Float

/* --- Adding variables to strings -- */
echo "<br />";
// Double quotes can be used to add variables to strings
echo "$name is $age years old";

// deprecated at php8.3
// echo "${name} is ${age} years old";

// Concatenate Strings


if($has_kids) {
echo '<p>He has Kids.</p>';
}

echo '<h3>' . 'He has ' . $cash_on_hand . ' BDT on hand.</h3>';

// Arithmetic Operators

echo 5 + 5;
echo "<br/>";
echo 10 - 6;
echo "<br/>";
echo 5 * 10;
echo "<br/>";
echo 10 / 2;
echo "<br/>";

// Constants - Cannot be changed
define('HOST', 'localhost'); // Old Way
const USER = 'root'; // Latest

var_dump(HOST, USER);

0 comments on commit 796029d

Please sign in to comment.