Introduction to Functions in PHP
Get started learning about functions in PHP so you can create your own reusable blocks of code.
StartKey Concepts
Review core concepts you need to learn to master this subject
PHP Variable Scope
return statement in PHP
Invoking a function in PHP
Define PHP Function
Camel Case Function
PHP Variable Scope
PHP Variable Scope
<?php
$x = 6;
function scope(){
$y = 7;
echo $x;
// prints 'undefined variable'
global $x;
echo $x;
// prints 6
echo $y;
// prints 7
}
scope();
A variable with local scope can only be accessed within the function it is declared. A variable with global scope can be accessed from multiple functions in the PHP script.
Introduction to PHP Functions
Lesson 1 of 1
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory