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

1. Create a file named: DataTypes3.php in your text editor. 2. Create an 6-pocke

ID: 3550201 • Letter: 1

Question

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

2.    Create an 6-pocket array with a mixture of integer and string values of your choice, echo two pockets of your choice, then echo the whole array using print_r.

3.    Re-assign one of the values in the array and then add a smaller array as a new pocket. Finally, echo the whole array using print_r.

4.    Create an associate array that contains your Last Name, then First Name.  Echo your full name appended together.  Then reassign your First Name and echo your 'new' full name again.

5.    Create a 5-pocket array of integers in random order.

6.    Demonstrate with labels: Count, Min, Max, Sort, Reverse Sort, Implode, Explode, and two in_array statements (one true, one false).

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

chicken
2013
Array ( [0] => 4 [1] => chicken [2] => 69 [3] => San Diego [4] => CIS [5] => 2013 ) 1

Array ( [0] => 4 [1] => cow [2] => 69 [3] => San Diego [4] => CIS [5] => 2013 [6] => Array ( [0] => apple [1] => pear [2] => fig ) ) 1

Barry Smith
Lawrence Smith

Count: 5
Max Value: 750
Min Value: 124
Sort: Array ( [0] => 124 [1] => 311 [2] => 432 [3] => 589 [4] => 750 )
Reverse Sort: Array ( [0] => 750 [1] => 589 [2] => 432 [3] => 311 [4] => 124 )
Implode: 750 & 589 & 432 & 311 & 124
Explode: Array ( [0] => 750 [1] => 589 [2] => 432 [3] => 311 [4] => 124 )

432 in array? 1
222 in array?



Explanation / Answer

<?php

//step 2

$arr1 = array("Hello","chicken","Bye",2013,2014,2016);

echo $arr1[2];

echo "<br/>";

echo $arr1[3];

echo "<br/>";

print_r ($arr1);

echo "<br/>";

//3 step

//reassign value

$arr1[0]="Hello World";

$newArr=array(1,2,3);

//add array as new pocket

$arr1[6]=$newArr;

//asscociative rray

$assArr = array("LastName"=>"watson","FirstName"=>"Jhon");

echo $assArr["FirstName"]." ".$assArr["LastName"];

echo "<br/>";

//reassign first name

$assArr["FirstName"]="steave";

echo $assArr["FirstName"]." ".$assArr["LastName"];

echo "<br/>";

//5-pocket array of integers in random order.

$intArr = array(5,4,8,2,1);

//6

echo "count: ".count($intArr);

echo "<br/>";

echo "Max Value: ".max($intArr);

echo "<br/>";

echo "Min Value: ".min($intArr);

echo "<br/>";

echo "sort: ".sort($intArr);

echo "<br/>";

echo "Reverse Sort: ".rsort($intArr);

echo "<br/>";

$imp = implode("&",$intArr);

echo "<br/>";

echo "Implode: ".$imp;

echo "<br/>";

echo "Explode: ";

print_r (explode("&",$imp));

echo "<br/>";

echo "4 in array? ".in_array(4,$intArr);

echo "<br/>";

echo "22 in array? ".in_array(22,$intArr);

echo "<br/>";

?>