From the course: PHP for Non-Programmers
Unlock the full course today
Join today to access over 25,200 courses taught by industry experts.
Creating the basic functionality: Flipping a coin once - PHP Tutorial
From the course: PHP for Non-Programmers
Creating the basic functionality: Flipping a coin once
- [Instructor] All right, first, let's make a basic program that will flip a coin once and display the results. So you can see, I have my REPL up here. It's a blank canvas, so let's get started. I will type the opening php tag and then I will create a variable called flip. I will say flip get and then I'll use that function random_int and random_int chooses from a range of provided integers. This is inclusive. So it'll include the first and second integer that you send and so I'm just going to say random_int zero, one. That way it will always pick between zero or one. With that, I will set up my if statement. So I'll say if one equals flip, then we want to echo Heads. And I'll add the HTML break here. Else, and I'll add a comment here. This means flip is zero. Echo Tails. And that's it, that's our whole program. So if we click Run, the first time we got heads, we can refresh. So now we got tails. And there's…
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.