Skip to content

Commit 0d11f98

Browse files
committed
updated chapter6
1 parent 12dc371 commit 0d11f98

File tree

8 files changed

+87
-2
lines changed

8 files changed

+87
-2
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:8.0-fpm
1+
FROM php:8.1.3-fpm
22

33
# Install system dependencies
44
RUN apt-get update && apt-get install -y git vim

hive

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if [ $# -gt 0 ];then
1616
fi
1717
if [ "$1" == "build" ]; then
1818
shift 1
19-
$COMPOSE build --parallel && $COMPOSE up
19+
$COMPOSE build && $COMPOSE up
2020
fi
2121
if [ "$1" == "test" ]; then
2222
shift 1

public/chapter6/arrayManip.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
$arr = array(5 => 1, 12 => 2);
3+
var_dump($arr);
4+
echo "<br />";
5+
6+
$arr[] = 56; // This is the same as $arr[13] = 56;
7+
// at this point of the script
8+
var_dump($arr);
9+
echo "<br />";
10+
11+
$arr["x"] = 42; // This adds a new element to
12+
// the array with key "x"
13+
var_dump($arr);
14+
echo "<br />";
15+
16+
unset($arr[5]); // This removes the element from the array
17+
var_dump($arr);
18+
echo "<br />";
19+
20+
unset($arr); // This deletes the whole array
21+
echo "<br /> Fatal error because it does not exist";
22+
23+
var_dump(arr);

public/chapter6/firstArray.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
$array1 = array(
4+
"foo" => "bar",
5+
"bar" => "foo",
6+
);
7+
8+
// Using the short array syntax
9+
$array2 = [
10+
"foo2" => "bar2",
11+
"bar2" => "foo2",
12+
];
13+
14+
var_dump($array1);
15+
echo '<br />';
16+
var_dump($array2);

public/chapter6/firstArray2.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
$array = array(
3+
"foo" => "bar",
4+
"bar" => "foo",
5+
100 => -100,
6+
-100 => 100,
7+
);
8+
var_dump($array);

public/chapter6/firstArray3.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
$array = array("foo", "bar", "hello", "world");
3+
var_dump($array);

public/chapter6/firstArray4.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
$array = array(
3+
"bar" => "foo",
4+
24 => 42,
5+
"multi" => array(
6+
"dimensional" => array(
7+
"array" => "foobar"
8+
)
9+
)
10+
);
11+
12+
var_dump($array["bar"]);
13+
var_dump($array[24]);
14+
var_dump($array["multi"]["dimensional"]["array"]);

public/chapter6/multiArray1.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
$cars = array (
3+
array("Subaru",21,17),
4+
array("Toyota",13,12),
5+
array("Lexus",6,8),
6+
array("Ford",14,10)
7+
);
8+
9+
echo $cars[0][0].": In available: ".$cars[0][1].", sold: ".$cars[0][2].".<br>";
10+
echo $cars[1][0].": In available: ".$cars[1][1].", sold: ".$cars[1][2].".<br>";
11+
echo $cars[2][0].": In available: ".$cars[2][1].", sold: ".$cars[2][2].".<br>";
12+
echo $cars[3][0].": In available: ".$cars[3][1].", sold: ".$cars[3][2].".<br>";
13+
14+
for ($row = 0; $row < 4; $row++) {
15+
echo "<p><b>Row #$row -- {$cars[$row][0]}</b></p>";
16+
echo "<ul>";
17+
for ($col = 1; $col < 3; $col++) {
18+
echo "<li>".$cars[$row][$col]."</li>";
19+
}
20+
echo "</ul>";
21+
}

0 commit comments

Comments
 (0)