Global scope

Author Topic: Global scope  (Read 154 times)

Offline beingchinmayTopic starter

  • Trade Count: (0)
  • Semi-Newbie
  • *
  • Thank You 0
  • Posts: 46
  • Karma: 0
  • Gender: Male
  • I am Chinmay
    • Fat Cutter
Global scope
« on: 11-26-2016, 02:33:42 »
Variables declared outside a function are global. That is, they can be accessed from any part of the program. However, by default, they are not available inside functions. To allow a function to access a global variable, you can use the global keyword inside the function to declare the variable within the function. Here’s how we can rewrite the update_counter( ) function to allow it to access the global $counter variable:


Code:
Only registered users can see contents. Please click here to Register or Login.
A more cumbersome way to update the global variable is to use PHP’s $GLOBALS array instead of accessing the variable directly:

Code:
Only registered users can see contents. Please click here to Register or Login.


 

Related Topics

  Subject / Started by Replies Last post
0 Replies
767 Views
Last post 08-20-2011, 00:05:09
by Vinil
0 Replies
1034 Views
Last post 07-12-2012, 03:53:11
by googinup
1 Replies
749 Views
Last post 05-04-2015, 23:20:40
by jaysh4922
0 Replies
602 Views
Last post 07-02-2016, 05:54:13
by chinmay.sahoo
0 Replies
289 Views
Last post 09-07-2016, 05:24:14
by beingchinmay