Objectives:
- To predict output in sight reading only
- To challenge existing knowledge in PHP
For this exercise, predict the output of given codes without seeking the console first. This skill is a must to learn when aiming to be a developer.
What do you think will be the output of the code below? Try to guess before running it!
$list = array(2,4,6,8);
foreach($list as $key => $value)
{
echo $key . " - " . $value ."<br />";
}
What would be the output of the following code? Try to guess before running it!
$list = array(2,4,6,8);
foreach($list as $value)
{
echo $value ."<br />";
}
What will be the output of this? Again, guess the output before running the code.
$fruits= array("A" => "Apple", "B" => "Banana");
foreach($fruits as $key => $value)
{
echo $key . " - " . $value ."<br />";
}
How about the following code? Try to guess the output of the code before running it!
$fruits= array("A" => "Apple", "B" => "Banana");
foreach($fruits as $key => $value)
{
echo $value ."<br />";
}
Let's change the echo statement. Make a guess!
$fruits= array("A" => "Apple", "B" => "Banana");
foreach($fruits as $key => $value)
{
echo $key ."<br />";
}
Okay. Now let's make it more challenging. What would be the output of the following code? ``` $plots = array( array("a1", "a2",...