1 00:00:00,000 --> 00:00:00,330 2 00:00:00,330 --> 00:00:02,860 >> DAVID MALAN: Let's write a program in PHP that prompts the user for an 3 00:00:02,860 --> 00:00:05,350 integer and then determines whether that integer is 4 00:00:05,350 --> 00:00:07,690 positive, 0, or negative. 5 00:00:07,690 --> 00:00:11,480 Here in conditions-1.php, I've already gotten us started by opening and 6 00:00:11,480 --> 00:00:13,160 closing a PHP tag. 7 00:00:13,160 --> 00:00:17,320 Let's first declare a variable, simply by doing $n. 8 00:00:17,320 --> 00:00:20,260 The dollar sign indicates that this is a variable, and notice that we don't 9 00:00:20,260 --> 00:00:21,770 need to provide a data type. 10 00:00:21,770 --> 00:00:24,900 >> Let's now call a function called readLine, which is similar in spirit 11 00:00:24,900 --> 00:00:29,300 to getString in the CS50 library for C. But readLine also takes an argument 12 00:00:29,300 --> 00:00:32,600 that specifies the prompt that you'd like to show to the user. 13 00:00:32,600 --> 00:00:36,660 For instance, I'd like an integer please. 14 00:00:36,660 --> 00:00:38,910 >> Let's now analyze the user's input. 15 00:00:38,910 --> 00:00:45,860 If n is greater than 0, then let's print out with printf, you picked a 16 00:00:45,860 --> 00:00:48,880 positive number. 17 00:00:48,880 --> 00:00:56,750 else if n equals 0, then let's print out with printf, you picked 0. 18 00:00:56,750 --> 00:01:01,560 And lastly, else if the number is presumably negative, let's print out 19 00:01:01,560 --> 00:01:06,680 with printf, you picked a negative number. 20 00:01:06,680 --> 00:01:11,540 >> Let's now save this file and pass it through to the PHP interpreter-- 21 00:01:11,540 --> 00:01:13,053 php conditions-1.php. 22 00:01:13,053 --> 00:01:16,010 23 00:01:16,010 --> 00:01:17,230 I'd like an integer please. 24 00:01:17,230 --> 00:01:19,510 How about 50? 25 00:01:19,510 --> 00:01:20,960 A positive number. 26 00:01:20,960 --> 00:01:23,195 >> Let's run it again with, say, 0. 27 00:01:23,195 --> 00:01:24,500 I picked 0. 28 00:01:24,500 --> 00:01:27,640 Let's run it again with, say, negative 50. 29 00:01:27,640 --> 00:01:29,430 And I indeed picked a negative number. 30 00:01:29,430 --> 00:01:34,330 But notice, most importantly, just how similar this syntax is to C. 31 00:01:34,330 --> 00:01:35,526