Question

In: Computer Science

.Variable created outside of function in the main script are available within the function. (Explain by...

  • .Variable created outside of function in the main script are available within the function. (Explain by giving an example)
    • a/
  • is it possible to include HTML in a PHP script file?explain by giving an example
  • here is a constant: define (“LocalHost”,”127.0.0.1”);
    • which one of the following is the correct way to refer to the above constant?
  • LocalHost
    • b.$LocaolHost
  • how many times will ”I love PHP programming!”be printed in the following program segment?
    • $count = 0
    • While ($count<10)
    • eco
  • the PHP function isset() only returns false if a parameter name is missing. It still returns true if the parameter name exists. True or false
  • Data submitted through the HTTP post method is store in array $_POST. True or false
  • Create an array and call it products that will contain the following key and value pairs:
    • i.”iphone “ :699
    • j.”blackberry” :300
    • k.”Samsung” :799
    • l.”Nokia” : 120
    • use a foreach loop to display the content of this array. Make sure to display both the key and value.
  • What will be the output of the following script?
    • <?php
      • $numbers = [100 , 200 ,300,400] ;
      • $values = array(“Hello”,”world”,from”,”csci2006” );
        • For ($i < count ( $numbers) ; $i++)
        • {              
          • echo “numbers[$i] = “ .$numbers[$i] . “<br /> “;
          • echo “values[$i] . “<br />”;
        • }
    • ?>
  • What classes of information are available via the $_server super global array?

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Question 1:

  • A variable declared outside any function considered as global variable in php.
  • To reference that variable need to declare that variable inside function using global keyword.

Here a new php file with name "SampleScript.php" is created, which contains following code.

SampleScript.php :

<?php

//declaring variable to store sum

$sum=0;

//function to add number

function addNumbers($num)

{

global $sum;/* reference to global scope variable */

$sum=$sum+$num;

}

//calling function to add numbers

addNumbers(10);

addNumbers(20);

addNumbers(30);

//displaying total

echo "Total :".$sum."<br/>";

?>

======================================================

Output : Open web page in the browser and will get the screen as shown below

Screen 1 :

**********************************

Question 2 :

  • Yes , Its possible to include HTML in PHP.
  • Consider below example

<?php

echo "<h1><i>This is from PHP</i></h1>";

?>

Output :When web page opened in the browser will get the screen as shown below.

************************************

Question 3 :

Answer :LocalHost

Explanation :Constant is not needed to access with $.

<?php

define ("LocalHost","127.0.0.1");

echo LocalHost;

?>

Output :After opening this in the browser will get the screen as shown below

***************************************

Question 4 :

Answer :Given code will print infinite time I love PHP programming! because there is no increment condition for i.Every time i will become true .Hence the output.

Code :

<?php

$count = 0;

while($count<10)

echo "I love PHP programming!";

?>

Output :

*******************************

Question 5 :

Answer: True

Explanation :isset() will return true if parameter exists otherwise false.

********************************************

Question 6 :

Answer :True

Explanation :Data submitted through the HTTP post method is store in array $_POST

***************************************

Question 7 :

Code :

<?php

//declaring array of smartphones

$smartPhones= array('iphone' => 699,

'blackberry'=>300,

'Samsung'=>799,

'Nokia'=>120);

//using for each to display key and value

foreach($smartPhones as $name => $price)

{

//display name and price

echo $name." ".$price."<br/>";

}

?>

Output :

***********************************

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

This is my code for an array using the bubblesort in the function outside of main....
This is my code for an array using the bubblesort in the function outside of main. My bubblesort is not working correctly , and I was told i'm missing a +j instead of +i in the function for void sorter.Can someone please help me with making my sorter work properly? everything else is fine and runs great. Thank you #include <stdio.h> #include <stdlib.h> #include <time.h> void printer(int *ptr, int length); void randomFill(int *ptr, int length); void sorter(int *ptr, int length);...
Please fix this python script, I keep getting a return outside function error and cannot get...
Please fix this python script, I keep getting a return outside function error and cannot get it to run: def caesar(plainText, shift):     cipherText = "" for char in plainText:     newChar = ord(char) + shift     if newChar > 128:       newChar = newChar % 128     finalChar = chr(newChar)     cipherText += finalChar return cipherText text = input("Enter a message: "); s = input("Enter the distance value: "); print (caesar(text, int(s)));
C Programming build a function that is outside of main domain but can be called Build...
C Programming build a function that is outside of main domain but can be called Build a function that will : - Take 3 arrays and their lengths as input: Array 1 for even numbers, Array 2 for odd numbers. Both 1 and 2 have the same size - put all elements in array 3 elements from array 1 should be placed in the even indexes and elements of array 2 should be placed in the odd indexes, in increasing...
1) Within the main function, the call to the constructor by defense of a class called...
1) Within the main function, the call to the constructor by defense of a class called MyClass is made by creating the firstClass object as follows. A) MyClass firstClass; B) MyClass firstClass (8); C) MyClass () firstClass; D) MyClass firstClass ();
Using the following array: //may be declared outside of the main function const int NUM_Games =4;...
Using the following array: //may be declared outside of the main function const int NUM_Games =4; //may only be declared within the main function int scores[NUM_GAMES] = {122, 76, 92, 143}; Write a C++ program to run a menu-driven program with the following choices: 1) Display the scores 2) Change a score 3) Display game with the highest score 4) Display a sorted list of the scores 5) Quit Write a function called getValidScore that allows a user to enter...
Suppose a function receives a pointer as an argument. Explain how this function is declared within...
Suppose a function receives a pointer as an argument. Explain how this function is declared within its calling function. In particular, explain how the data type of the pointer argument is represented. C++
Explain the three situations whereby the production point is located within the PPC, on the PPC and outside the PPC?
Explain the three situations whereby the production point is located within the PPC, on the PPC and outside the PPC?
Assignment Description: In this assignment, a script file should be created to contain a set a...
Assignment Description: In this assignment, a script file should be created to contain a set a SQL statements for the Pretty Prints Company to better manage their business. Use the database created for Pretty Prints in Assignment 2. Include the SQL statements to satisfy the following queries. The following queries should be included in the script: Create a view named Under_100. It consists of the item_id, title, artist, unit_price and order_qty for every print with a unit_price under 100 dollars....
Explain the function/purpose of the following section of the script -- Set environment variables SET FEEDBACK...
Explain the function/purpose of the following section of the script -- Set environment variables SET FEEDBACK OFF SET HEADING OFF SET VERIFY OFF Explain the function/purpose of the following section of the script PROMPT ********** Create New Order ********** PROMPT SELECT 'Date: ', TO_CHAR(SYSDATE,'MM/DD/YYYY') FROM DUAL; PROMPT Explain the function/purpose of the following section of the script DEFINE v_cus_lname = 'Customer Not Found' DEFINE v_cus_fname = 'Customer Not Found' DEFINE v_cus_phone = 'N/A' Explain the function/purpose of the following section...
Conduct outside research on the D.E.S.C Script for Assertiveness. Discuss why it may be important as...
Conduct outside research on the D.E.S.C Script for Assertiveness. Discuss why it may be important as a leader to write a D.E.S.C script for a conflict situation. Choose a situation that may be a conflict situation, and describe the situation. Then, prepare a D.E.S.C. script for that situation. Evaluate this tool as to whether you would use it in a leadership role. What are its benefits and drawbacks?​
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT