This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$names = array ("Ben", "John", "Gerry", "Harry"); | |
print_r ($names); | |
echo"<br>"; | |
var_dump ($names); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$user = array ("first name" => "Barry", | |
"last name" => "Toppings", | |
"age" => 32, | |
"email" => "example@me.com" | |
); | |
print_r ($user); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$number1 = 4; | |
$number2 = 12; | |
$number3 = 50; | |
$addition = $number1 + $number2; | |
$subtraction = $number1 - $number3; | |
$division = $number3 / $number1; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$age = 74; | |
if($age >= 18 && $age <= 70 ){ | |
echo "Welcome to the casino"; | |
}elseif ($age <= 17) { | |
echo "You are not old enough"; | |
}else { | |
echo "You should not be spending your pension on gambling"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$number =90; | |
switch($number){ | |
case 50; | |
echo "it is 50"; | |
break; | |
case 60; | |
echo "it is 60"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$numbers = array(23,56,45,78,43,123); | |
foreach ($numbers as $number){ | |
echo $number . "<br>"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function calculate (){ | |
echo 356 + 4768; | |
} | |
calculate (); | |
echo "<br>"; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ob_start(); | |
session_start(); | |
//database credentials | |
define('DBHOST','localhost'); | |
define('DBUSER','username'); | |
define('DBPASS','password'); | |
define('DBNAME','database name'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servername = "localhost"; | |
$username = "username"; | |
$password = "password"; | |
try { | |
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password); | |
// set the PDO error mode to exception | |
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
echo "Connected successfully"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servername = "localhost"; | |
$username = "username"; | |
$password = "password"; | |
$dbname = "myDBPDO"; | |
try { | |
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); | |
// set the PDO error mode to exception | |
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |