From the course: PHP for Non-Programmers
Unlock the full course today
Join today to access over 25,200 courses taught by industry experts.
What are functions? - PHP Tutorial
From the course: PHP for Non-Programmers
What are functions?
- [Instructor] Sometimes you have some code you want to easily reuse. It could be multiple lines that you use over and over again, or a common piece of functionality that will get used regularly. Reuse and abstraction are important concepts in programming and functions are the linchpin of those concepts. Functions are reusable snippets of code that can be called multiple times. You can imagine functions as variables for a block of code. Functions are formatted like this. You can see we have function hello_world, a set of parentheses, curly braces, and then whatever code we want to execute. In this case, we are echoing hello world. Each function starts with the keyword function, followed by the name of the function, this could also be called the signature, then parenthesis and an opening curly brace. The function ends with a closing curly brace. We call or use the above function by writing the signature, so hello underscore…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.