148k views
0 votes
Look at the PHP code below. Write a PHP "for "statement that iterates through the Sfruits array. Please note do not use VARDUMP, or a foreach statement. Write your code and test it on a Web emulator and take a screen capture of the working code and paste it below Sfruits array Apple', IBM', Zerox', Stratus', 'Aspire 2. Look at the PHP code below. Write a PHP "foreach" statement that iterates through the $fruits array. Please note do not use VARDUMP, or a for statement. Write your code and test it on a Web emulator and take a screen capture of the working code and paste it below. Sfruits array Apple', 'IBM', Zerox', Stratus', 'Aspire *) 3. Look at the PHP code below. Which arguments are default arguments and how do you know? function foo( SargA, SargB 5, SargC 10) echo "argA:". SargA. ""; echo "argB: ". SargB. "" echo "argC:". SargC. "" 5. Look at the PHP code below. What which arguments are optional and how do you know? Hint: Be careful. If you are not 100% positive, look it up in the presentation. function foo Sargx, Sargl ", Sarg2 =") { echo "argx: Sargx "; echo "argl: Sargl "; echo "arg2: Sarg2 ";

1 Answer

0 votes

Answer:

The answer to this question can be given as:

code 1:

<?php

//define 1-D array

$fruits = array('Apple', 'IBM', 'Zerox', 'Stratus', 'Aspire');

for($k = 0; $k < count($fruits); $k++) //use for loop.

{

echo $fruits[$k]." "; //print values.

}

?>

Code 2:

<?php

//define 1-D array

$fruits = array('Apple', 'IBM', 'Zerox', 'Stratus', 'Aspire');

foreach($fruits as $element) //use foreach loop

{

echo $element." ";

//print values.

}

?>

code 3:

Answer:In this code default arguments are $argB ,$argC because they are define if we don't pass value to these argument so it will take default value.

<?php

function foo($argA, $argB = 5, $argC = 10) //define function

{

echo"argA: ".$argA;

echo " ";

echo"argB: ".$argB;

echo " ";

echo"argC: ".$argC;

}

foo("abc");

//calling function

?>

code 4:

Answer: The variable $arg1 and $arg2 are optional arguments. If we want to pass the value to them so they take that value otherwise they use there default value.

<?php

function foo($argx, $arg1 = '', $arg2 ='') //define function.

{

echo"argx: ".$argx; //print value

echo " ";

echo"arg1: ".$arg1;

echo " ";

echo"arg2: ".$arg2;

}

foo("abc"); //calling function

?>

Explanation:

In this question there are 4 code that can be explain as:

In all the code all the working done in the php script that is

<?php

//codes

?>

In code 1 we define 1-D array.In this array we insert elements and use the for loop for print all elements. In php echo is used for print elements.

In code 2 we define the 1-D array in the array we pass the value and use the foreach loop for print all the value. In the PHP foreach loop is a special loop, it is used for print key and value.

In code 3 we define the function that is function foo().In function we pass three variable that is $argA, $argB and $argC. In variable $arg we don't pass any value. but in the other two variables, we pass the value that shows both 2 variables are default arguments because they are defined. If we don't pass the value to these arguments so it will take default value. Then we call the function and print its value.

In code 4 we define the function that is function foo().In function we pass three variable that is $argx, $arg1 and $arg2. In this variable, we don't pass any value. We only assign the value in the first variable because

The variable $arg1 and $arg2 are optional arguments. If we want to pass the value to them so they take that value otherwise they use their default value. Then we call the function and print its value.

Look at the PHP code below. Write a PHP "for "statement that iterates through-example-1
Look at the PHP code below. Write a PHP "for "statement that iterates through-example-2
Look at the PHP code below. Write a PHP "for "statement that iterates through-example-3
Look at the PHP code below. Write a PHP "for "statement that iterates through-example-4
User Vasilis Greece
by
4.8k points