PHP: Arrays


Array 1: Family

Array ( [0] => Chris [1] => Inga [2] => Reow Reow [3] => Chomp )

Array 2: Food

array(4) { [0]=> string(5) "pizza" [1]=> string(8) "sandwich" [2]=> string(4) "soup" [3]=> string(5) "chili" }


Array 3: Countries /w Language

array(4) { ["france"]=> string(6) "french" ["usa"]=> string(7) "english" ["germany"]=> string(6) "german" ["Japan"]=> string(8) "Japanese" }

Count of Array 3 is: 4!


Array 4: Names

array(5) { ["first_name"]=> string(11) "Christopher" ["middle_name"]=> string(7) "Cameron" ["last_name"]=> string(9) "Reow Reow" ["age"]=> int(37) ["dob"]=> string(4) "0827" }


Array 5: Levels

array(3) { [1]=> array(2) { ["name"]=> string(7) "Level 1" ["description"]=> string(18) "This is level one." } [2]=> array(2) { ["name"]=> string(7) "Level 2" ["description"]=> string(18) "This is level two." } [3]=> array(2) { ["name"]=> string(7) "Level 3" ["description"]=> string(20) "This is level three." } }


The code used for index.php is below:


<!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">
    <link rel="stylesheet" href="../styles.css">
    <title>PHP: Arrays</title>
</head>
<body>
    
</body>
</html>

<h1 class="lesson-h1">PHP: Arrays</h1>

<?php

// Array 1 Code //////////////////////////////////////
echo "<hr><h3>Array 1: Family</h3>";
$myArray = array("Chris", "Inga", "Reow Reow", "Chomp");

print_r($myArray);

// Array 2 Code //////////////////////////////////////
echo "<hr><h3>Array 2: Food</h3>";
$food[0] = "pizza";

$food[1] = "sandwich";

$food[2] = "soup";

$food[3] = "chili";

echo "<p>".var_dump($food)."</p>";

// Array 3 Code //////////////////////////////////////
echo "<hr><h3>Array 3: Countries /w Language</h3>";
$thirdArray = array("france" =>"french", "usa" =>"english", "germany" =>"german", "Japan" => "Japanese");

echo "<p>".var_dump($thirdArray)."</p>";

echo "<p><strong>Count</strong> of Array 3 is: ".sizeof($thirdArray)."!</p>";

// Array 4 Code //////////////////////////////////////
echo "<hr><h3>Array 4: Names</h3>";
$names = ["first_name" => "Christopher", "middle_name" => "Cameron", "last_name" => "Reow Reow", "age" => 37, "dob" => "0827"];
echo "<p>".var_dump($names)."</p>";

// Array 5 Code //////////////////////////////////////
echo "<hr><h3>Array 5: Levels</h3>";
$levels = array(
    1 => array(
        'name' => 'Level 1',
        'description' => 'This is level one.'
    ),
    2 => array(
        'name' => 'Level 2',
        'description' => 'This is level two.'
    ),
    3 => array(
        'name' => 'Level 3',
        'description' => 'This is level three.'
    ) 
);
echo "<p>".var_dump($levels)."</p>";

include('../show_code.php');
show_code('index.php');
?>