Posted on Leave a comment

Jyrone Parker Live – More Data Types, Flow Control Logic, File I/O

[callaction url=”″ background_color=”#333333″ text_color=”#ffffff” button_text=”Go Now” button_background_color=”#e64429″]Subscribe To My Youtube Page[/callaction]

Three Days In!

Three days in three live streams! In today’s live stream I go over the last couple data types, arrays and closures. Array hold a collection of items such as an array of grocery prices, or an array of color codes. They can be either single dimensional or multi dimensional and they can also be associative. Some examples of arrays include:

$x = [1,2,3,4,5];
$y = [
"favorite_food" => "Fried Chicken",
"favorite_spice" => "Hot Sauce"
$z = [
"data" => [
"result" => 1,
"error_code" => 502
"message" => "Hello"
// Access arrays
echo $x[0]; // first element in array
echo $y["favorite_food"];//access by name
echo $z["data"]["result"]; // accessing multidimensional array elements

Flow Control Logic

I also went over control flow logic. Many times in your application you are going to need to take certain actions based on certain actions the three basic flow control structures are: if/else statements, loops, and switch statements, some examples are as follows.

//if/else statment
if($x[0] % 2){
echo "Even";
echo "Odd";
//while loop
while($x == true){
echo "Running....";
for($i = 0; $i<count($x); ++$i){
echo $x[$i];
foreach($x as $key=>$value){
echo $value;
case 'Hyundai':
echo "Hyundai";
case "Ford":
echo "Ford";
echo "IdK";


File I/O

Lastly I went over file input/output including opening files and closing files:

$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);

Don’t forget to subscribe to my YouTube channel and to subscribe to this blog to learn more!