PHP Basic Case 3: Determining Student Constellations
1. Demand Analysis
The zodiac sign is matched based on the birth month and day (11th to 14th digit); for example, when the birth date is between March 21st and April 19th, it is Aries, and other Click here to continue writing the horoscope.
2. Design ideas
1. The division of constellations is the interval between two dates. When the date is less than the 10th of the student's birth date, how to prevent comparison errors?
2. How to judge the constellation?
3. Knowledge Reserve
1. In PHP, the following conditional statements are provided:
· but can execute code when the condition is true. · : -Ternary operator
if...else statement - executes a piece of code when the condition is true, and executes another piece of code when the condition is not true. ....else statement - executes a code block when one of several conditions is true
· switch statement - executes a code block when one of several conditions is true
2, if statement
is used to execute code only when the specified condition is true.Grammar
if (条件) { 条件成立时要执行的代码; }
3, if...else statement
Execute a block of code when the condition is true, and execute it when the condition is not true Another piece of code.Grammar
if (条件) { 条件成立时执行的代码; } else { 条件不成立时执行的代码; }
4. if...else if...else statement
Between several conditions Execute a block of code when established..
Syntax
if (条件) { if 条件成立时执行的代码; } else if (条件) { elseif 条件成立时执行的代码; } else { 条件不成立时执行的代码; }
5. Switch statement
I hope to selectively execute one of several code blocks.Grammar
switch (n) { case label1: 如果 n=label1,此处代码将执行; break; case label2: 如果 n=label2,此处代码将执行; break; default: 如果 n 既不等于 label1 也不等于 label2,此处代码将执行; }
4. Code implementation1. Define variables to save student information
$name = '王六';//保存学生的姓名 $birth = '2003-08-07'; //保存学生的出生日期
2. Segmentation String, get the year, month, and day of the student's birth
$temp = explode('-',$birth); $stu_by = $temp[0]; $stu_bm = $temp[1]; $stu_bd = $temp[2];
3. Get the year, month, and date of the current time
$cur_y = date('Y'); //4位数字完整表示的年份 $cur_m = date('n'); //数字表示的月份,没有前导零,1~12 $cur_d = date('j'); //月份中的第几天,没有前导零,1~31
4. Determine whether the student's date is a two-digit number
if($stu_bd < 10){ $stu_bd = '0'.$stu_bd; }
$date = "$stu_bm.$stu_bd";
5. Determine the constellation
if($date >=1.21 && $date <= 2.19){ $const = '水瓶座'; }elseif($date >=2.20 && $date <= 3.20){ $const = '双鱼座 }elseif($date >=3.21 && $date <= 4.20){ $const = '白羊座'; }elseif($date >=4.21 && $date <= 5.21){ $const = '金牛座'; }elseif($date >=5.22 && $date <= 6.21){ $const = '双子座'; }elseif($date >=6.22 && $date <= 7.22){ $const = '巨蟹座'; }elseif($date >=7.23 && $date <= 8.23){ $const = '狮子座'; }elseif($date >=8.24 && $date <= 9.23){ $const = '处女座'; }elseif($date >=9.24 && $date <= 10.23){ $const = '天秤座'; }elseif($date >=10.24 && $date <= 11.22){ $const = '天蝎座'; }elseif($date >=11.23 && $date <= 12.21){ $const = '射手座'; }else{ $const = '魔羯座'; }
5. Result display
The above is the detailed content of PHP Basic Case 3: Determining Student Constellations. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.
