Tell me how can we define a variable accessible in functions of a php script?



Tell me how can we define a variable accessible in functions of a php script?..

Answer / Kavendra Singh Sagar

To define a variable that is accessible in functions of a PHP script, you should use the global keyword. Here's an example:nn```phpnfunction myFunction() {n global $myVar;n // You can now access and modify $myVar inside this functionn}n$myVar = 'example';nmyFunction();n$myVar = 'modified';n``

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

What are the Merits and De-Merits of CURL library ?

1 Answers  


what the new feature add in php 7.2?

1 Answers  


how to display and include the user system date/time in a php program/project

1 Answers   Wipro,


What are the new features available in php 7?

1 Answers  


What is the difference server side and browser side validation?

1 Answers  


Tell me how can we get the error when there is a problem to upload a file?

1 Answers  


Explain how you can update memcached when you make changes to php?

1 Answers  


Which methods should be used for sending an email using the variables $to, $subject, and $body?

1 Answers  


How can i send a HTML file to mail account.

2 Answers  


How can you pass a variable by reference?

1 Answers  


What is prepared statement in php?

1 Answers  


What does php do?

1 Answers  


Categories