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

Question 4 A. a) Create a numeric array called numbers to store 10 self-defined

ID: 3709949 • Letter: Q

Question

Question 4 A. a) Create a numeric array called numbers to store 10 self-defined integer numbers by b) Create an array named mySuperHeroes by using [ to store your favourite three c) Create an array to store your own personal details like name, gender (Male/ Female) using array () function. super heroes age, weight (in kg) and height (in cm). Name this array as your name in camel case naming. d) Create an associative array to store the following data: Key Value JH Johor KH Kedah KN Kelantan KLKuala Lumpur LA Labuan ME Melaka NS Negeri Sembilan PH Pahan PK Perak PL Perlis PG Pulau Pinan PJ Putrajava SASabah SK Sarawak SL Selangor TE Terengganu Save the document as ArrayCreations.php Write a server script to display array elements for all the arrays that created in Question 1 (a to d) by using a) while loop b) foreach loop Save the document as ArrayOutput.php Define an associative array for days of the week. The format as showing in below 1: Monday, 2: Tuesday, ..., 7: Sunday Output all elements into an unordered list Save the document as DaysOfWeek.php Assume, $str"gdujogfjemiztksyawxrnlbhbzfpdetpovsyxeqhbgkncarklol" Count the letter of occurrence in the string above and display the findings. Save the document as CountLetters.php

Explanation / Answer

ArrayCreation.php
*********************

<?php
$numbers = array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
$MySuperHeros = array("Batman", "Spiderman", "Superman");
$MadhavKacha = array("Name"=>"MadhavKacha","Gender"=>"M","Age"=>"33","Weight"=>"75kg","Height"=>"182cm");
$arr2= array("JH"=>"Johor","KH"=>"Kedah","KN"=>"Kelantan","KL"=>"Kuala Lumpur","LA"=>"Labuan","ME"=>"Melaka","NS"=>"Negeri Sembilan","PH"=>"Pahang","PK"=>"Perak","PL"=>"Perlis","PG"=>"Pulau Pinang","PJ"=>"Putrajaya","SA"=>"Sabah","SK"=>"Sarawak","SL"=>"Selangor","TE"=>"Terengganu");
$keys = array_keys($arr2);
$keys2 = array_keys($MadhavKacha);

?>

ArrayOutput.php
********************

<?php
include 'ArrayCreations.php';
echo "<br>";
echo "Output of Q-A"."<br>";
echo "<br>";
foreach( $numbers as $value ) {
            echo "Value is $value <br />";
         }
echo "<br>";      
echo "Output of Q-B"."<br>";
echo "<br>";
foreach( $MySuperHeros as $name ) {
            echo "$name <br />";
         }
echo "<br>";
echo "Output of Q-C"."<br>";
echo "<br>";
print_r(($MadhavKacha));
echo "<br>";
echo "Output of Q-D"."<br>";
echo "<br>";
echo "foreach associative array.........................."."<br>";
echo "<br>";
foreach ($arr2 as $key=>$value)
{  
   echo $key ." ", $value ."<br>";
}

echo "<br>";
echo "Using While Loop";
echo "Output of Q-A"."<br>";
echo "<br>";

$i = 0;
while ($i < count($numbers))
{
    echo $numbers[$i];
   echo "<br>";
    $i++;
}
echo "<br>";
echo "Using While loop";
echo "<br>";      
echo "Output of Q-B"."<br>";
echo "<br>";
$i = 0;
while ($i < count($MySuperHeros))
{
    echo $MySuperHeros[$i];
   echo "<br>";
    $i++;
}
echo "<br>";
echo "Using While loop";
echo "<br>";
echo "Output of Q-C"."<br>";
echo "<br>";
while (!empty($keys2)) {
    $key = array_pop($keys2);
    echo $key . ' = ' . $MadhavKacha[$key] . '<br />';
}

echo "<br>";
echo "Output of Q-D"."<br>";
echo "<br>";
echo "While loop associative array.........................."."<br>";
echo "<br>";
while (!empty($keys)) {
    $key = array_pop($keys);
    echo $key . ' = ' . $arr2[$key] . '<br />';
}
?>

DaysOfWeek.php
********************

<?php

$days = array("1"=>"Monday","2"=>"Tuesday","3"=>"Wednesday","4"=>"Thursday","5"=>"Friday","6"=>"Saturday","7"=>"Sunday");
echo '<ul>';
foreach($days as $key=>$value){
echo '<li>'.$key ." ". $value.'</li>';
}
echo '</ul>';
?>

CountLetters.php
********************

<?php
$str = "gdujogfjemiztksyalxrnlbhbzfpdetpovsyxeqhbgkncarklol";

$ascii_val = ord("a");
for($i=$ascii_val;$i<$ascii_val+26;$i++)
{
echo "The occurance of char ". chr($i)." " .substr_count($str, chr($i))."<br>";
}
?>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote