Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create a file named: DataTypes4.php in your text editor. 2. Create two variab

ID: 3550202 • Letter: 1

Question

1.    Create a file named: DataTypes4.php in your text editor.

2.    Create two variables ($Bool1, $Bool2) setting the first one to True and the second one to False. Output each variable.

3.    Set four variables: Var1 to any integer, Var2 to null, Var3 to any string, Var4 to 0 (zero with no quotes).

4.    Demonstrate with labels: if each variable is set, is null, and is empty.

5.    Set three variables: Var5 to any integer, Var6 to your full name, Var7 to Var6 + a three-digit integer.

6.    Demonstrate with labels: what each variable's (Var5, Var6, Var7) type is.

7.    Cast Var5 to a string using settype.  Cast Var6 to an integer using the declaration (integer).

8.    Demonstrate with labels: what each variable's (Var5, Var6) type is.

9.    Set a new variable (Var8) to the integer 108 & define a constant CIS_PHP to 108.  Echo both of these with labels.

10. Increment Var8 by 10 (+=) and define CIS_PHP to 118.  Echo both of these with labels.  You will either get an error for trying to redefine the constant or the redefining will be ignored.

11. Here is a sample of what your output should look like.

$bool1: 1
$bool2:

$var1 is set: 1
$var2 is set:
$var3 is set: 1
$var4 is set: 1

$var1 null:
$var2 null: 1
$var3 null:
$var4 null:

$var1 empty:
$var2 empty: 1
$var3 empty:
$var4 empty: 1

Type? integer
Type? string
Type? integer

Type? string
Type? string

Variable: 108
Constant: 108

Variable: 118
Constant: 108


Explanation / Answer

<?php

//two variables

$Bool1=True;

$Bool2=False;

//2 requirement

echo "$Bool1: ".$Bool1,PHP_EOL;

echo "$Bool2: ".$Bool2,PHP_EOL;


//3 reqirement

$Var1=1;

$Var2=NULL;

$Var3="Any String";

$Var4=0;


//4th reqirement

echo "$Var1 is set: ".isset($Var1),PHP_EOL;

echo "$Var2 is set: ".isset($Var2),PHP_EOL;

echo "$Var3 is set: ".isset($Var3),PHP_EOL;

echo "$Var4 is set: ".isset($Var4),PHP_EOL;


echo "$Var1 null: ".is_null($Var1),PHP_EOL;

echo "$Var2 null: ".is_null($Var2),PHP_EOL;

echo "$Var3 null: ".is_null($Var3),PHP_EOL;

echo "$Var4 null: ".is_null($Var4),PHP_EOL;


echo "$Var1 empty: ".is_null($Var1),PHP_EOL;

echo "$Var2 empty: ".is_null($Var2),PHP_EOL;

echo "$Var3 empty: ".is_null($Var3),PHP_EOL;

echo "$Var4 empty: ".is_null($Var4),PHP_EOL;


//5th step

$Var5=5;

$Var6="Name";

$Var7=$Var6 + 333;


//step 6

echo "Type of Var5? ".gettype($Var5),PHP_EOL;

echo "Type of Var6? ".gettype($Var6),PHP_EOL;

echo "Type of Var7? ".gettype($Var7),PHP_EOL;


//7th step

settype($Var5,"string");

settype($Var6,"integer");


//8th step

echo "Type of Var5? ".gettype($Var5),PHP_EOL;

echo "Type of Var6? ".gettype($Var6),PHP_EOL;


//9th step

$Var8=108;

define('CIS_PHP', '108');

echo "Variable: ".$Var8,PHP_EOL;

echo "Constant: ".CIS_PHP,PHP_EOL;


//10th step

$Var8+=10;


define('CIS_PHP', '118');

echo "Variable: ".$Var8,PHP_EOL;

echo "Constant: ".CIS_PHP,PHP_EOL;



?>