From the course: PHP for Non-Programmers
Unlock the full course today
Join today to access over 25,200 courses taught by industry experts.
Writing your own functions - PHP Tutorial
From the course: PHP for Non-Programmers
Writing your own functions
- [Instructor] Now that you know a bit about functions, let's walk through writing our own, something that can actually work in a real program instead of in just the abstract. Our function will flip a coin some number of times and report the total number of heads and tails. The number of flips can be sent by the user, but we will hard-code it for now. So first let's define our function. We'll say function, multiple_flips, and then we'll pass an argument called num_flips. Notice the naming convention here. Each word is lowercase, and spaces are replaced by underscores. We're passing one argument, the number of flips, which will get assigned to the variable, num_flips. Next, we need to define some other helpful variables. So the first will be our incrementer, which will start i gets zero, then we want a heads count. So we'll do heads_count, also gets zero, and a tails count and again, that will get zero. I is our…
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.