-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask4.php
30 lines (26 loc) · 973 Bytes
/
task4.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
/**
* Author : Fabio Pinto
* Description as per requirements :
* Using page 385 as a guide, create and use two functions to illustrate two methods to access a variable
* from within a function. The outcome should look like the screenshot below:
**/
//Variable with global scope
$sentence = 'The dog ate my homework';
//Method 1 to access global variable from within function
function method1() {
global $sentence;
echo $sentence;
}
//Method 2 to access global variable fron within function
function method2() {
$sentence = $GLOBALS['sentence'];
echo $sentence;
}
//Printing and function calls to create desired output
echo '<u>Access a global variable from within a function: Method 1</u></br>'; method1();
echo '</br></br><u>Access a global variable from within a function: Method 2</u></br>'; method2();
?>
</br><a href="index.html">Back...<a>
</br><iframe src="task4.txt" height="400" width="1200">
<p>Your browser does not support iframes.</p></iframe>