Thursday, August 11, 2022

Associative Arrays in Php | PHP Tutorial #18

 


youtube:

https://www.youtube.com/watch?v=yJNeEGvskpw&list=PLu0W_9lII9aikXkRE0WxDt1vozo3hnmtR&index=18

Blogspot:

https://www.codewithharry.com/videos/php-tutorials-in-hindi-18/




<?php

echo "Welcome to associative array PHP tutorial class<br>";

$favcol = array("Sourav"=>"red",
                "Ram"=> "blue",
                "Pratyush" => "green");

//  echo $favcol["Pratyush"];      

foreach ($favcol as $key => $value) {
    echo "<br>Favourite colour of $key is $value";
}


?>

Date Function: Handling Dates in Php | PHP Tutorial #17

 youtube:

https://www.youtube.com/watch?v=rCsAqa1N0kc&list=PLu0W_9lII9aikXkRE0WxDt1vozo3hnmtR&index=17


Blogspot:

https://www.codewithharry.com/videos/php-tutorials-in-hindi-17/


<?php
echo "Welcome to the world of dates<br>";
// $d = date("dS F Y");
$d = date("dS F Y, g:i A");
echo "Todays date is $d <br>";
// Quick Quiz - Post at least 3 examples of dates in php in the comments below

// Prints something like: Monday 8th of August 2005 03:12:46 PM
echo date('l jS \of F Y h:i:s A');
 
$year = date("Y");
echo "<br>";
echo "Copyright $year | All rights reserved <br>";

?>

Functions in Php | PHP Tutorial #16

 youtube:

https://www.youtube.com/watch?v=8Bfnmeer18M&list=PLu0W_9lII9aikXkRE0WxDt1vozo3hnmtR&index=16


Blogspot:

https://www.codewithharry.com/videos/php-tutorials-in-hindi-16/


<?php
echo "Welcome to php tutorial on functions <br>";

function processMarks($marksArr){
    $sum = 0;
    foreach ($marksArr as $value) {
        $sum += $value;
    }
    return $sum;
}

function avgMarks($marksArr){
    $sum = 0;
    $i = 1;
    foreach ($marksArr as $value) {
        $sum += $value;
        $i++;
    }
    return $sum/$i;
}

$rohanDas = [34, 98, 45, 12, 98, 93];
// $sumMarks = processMarks($rohanDas);
$sumMarks = avgMarks($rohanDas);

$harry = [99, 98, 93, 94, 17, 100];
// $sumMarksHarry = processMarks($harry);
$sumMarksHarry = avgMarks($harry);
echo "Total marks scored by Rohan out of 600 is $sumMarks <br>";
echo "Total marks scored by Harry out of 600 is $sumMarksHarry";

?>

foreach Loops in php | PHP Tutorial #15

 Youtube:

foreach Loops in php | PHP Tutorial #15


Blogpost:

https://www.codewithharry.com/videos/php-tutorials-in-hindi-15/



Code as described/written in the video

<?php
echo "Welcome to the world of foreach loops <br>";
$arr = array("Bananas", "Apples", "Harpic", "Bread", "Butter");

// for ($i=0; $i < count($arr); $i++) { 
//     echo $arr[$i];
//     echo "<br>";
// }

// Better way to do this - foreach loops
foreach ($arr as  $value) {
    echo "$value <br>";
}

?>