Project: Personal Information Card
Time to put your data type knowledge into practice. You'll create a PHP script that displays a formatted personal information card using all five basic data types we've covered. This isn't just another "hello world" exercise - you'll build something that demonstrates real-world data handling patterns.
Assignment
Create a single PHP file that displays a personal information card containing various details about a person. Your script must demonstrate proper use of strings, integers, floats, booleans, and null values while producing clean, readable output.
The final result should look professional enough that someone could actually use it as a digital business card or contact information display.
Learning Objectives
By completing this project, you'll demonstrate your ability to:
- Declare and initialize variables using all five basic data types
- Apply proper variable naming conventions and PHP syntax
- Perform type conversions and basic calculations
- Format output for human readability
- Combine different data types in meaningful ways
- Handle conditional logic based on boolean values
Requirements
Your personal information card must include the following elements, each demonstrating specific data types:
String Data (3 different examples)
- Full name
- Job title or profession
- Email address or website URL
Integer Data (2 different examples)
- Age or years of experience
- Phone number (as digits) or postal code
Float Data (2 different examples)
- Height in feet/meters
- A rating or score (like 4.8/5.0 stars)
Boolean Data (2 different examples)
- Availability status (available for work, accepting projects, etc.)
- A yes/no preference (remote work, travel willingness, etc.)
Null Value (1 example)
- An optional field that might not be filled (like middle name, spouse name, or secondary phone)
Additional Requirements
- Calculate and display at least one derived value (like age in days, BMI, or years until retirement)
- Use proper string concatenation and variable interpolation
- Include conditional output based on boolean values
- Format numbers appropriately (currency, percentages, etc.)
Step-by-Step Approach
Don't try to build everything at once. Break this down into manageable pieces:
Step 1: Set Up Your Variables
Start by declaring all your variables with appropriate values. Focus on choosing realistic data and meaningful variable names.
<?php
// Start with something like this, then expand
$firstName = "Sarah";
$lastName = "Johnson";
$age = 28;
// ... add more variables
?>
Step 2: Basic Output
Get simple output working first. Don't worry about formatting yet - just make sure you can display all your data.
Step 3: Add Calculations
Implement your derived calculations. Maybe calculate age in days, or determine a completion percentage for something.
Step 4: Conditional Logic
Add conditional output based on your boolean values. Show different messages or information depending on the boolean states.
Step 5: Polish the Formatting
Make the output look professional. Add proper spacing, labels, and formatting for different data types.
Example Output Structure
Your finished card should produce output similar to this (but with your own data and styling):
=== PERSONAL INFORMATION CARD ===
Name: Sarah Johnson
Title: Senior Web Developer
Email: [email protected]
Age: 28 years (10,227 days old)
Height: 5.6 feet
Experience Rating: 4.2/5.0
Phone: 555-0123
Location: San Francisco, CA
Status: ✓ Available for freelance projects
Remote Work: ✓ Open to remote opportunities
Spouse: Not specified
=== CALCULATED METRICS ===
Days until 30th birthday: 731 days
Professional experience: 6 years
Don't copy this exact format - create your own structure that makes sense for your data and looks good to you.
Tips for Success
Start with working code, then improve it. Get something basic running first, then add features incrementally. A simple working version is better than a complex broken one.
Use meaningful variable names. Instead of $x
or $data
, use names like $yearsExperience
or $isAvailableForWork
that explain what the data represents.
Test your calculations carefully. If you're calculating age in days or other derived values, verify the math is correct. Use simple test cases where you know the expected result.
Pay attention to data types. Make sure you're actually using all five required types. Use var_dump()
if you need to verify what type a variable contains.
Format output for humans. Raw numbers like 10227
are harder to read than formatted versions like 10,227
. Use functions like number_format()
to make your output more readable.
Common Pitfalls to Avoid
Don't use fake or placeholder data. Use realistic values that someone might actually have on their business card. This makes the project more engaging and practical.
Don't neglect the null value requirement. It's easy to forget about null since it represents absence of data. Think about what information someone might legitimately not want to share or might not have.
Don't overcomplicate the conditional logic. Simple if statements are fine. You don't need complex nested conditions for this project.
Don't ignore type conversions. If you need to do math with string data, convert it explicitly rather than relying on PHP's automatic type juggling.
Extension Challenges
Once you have the basic requirements working, try these optional enhancements:
- Add data validation (check if email looks valid, age is reasonable, etc.)
- Create multiple output formats (HTML table, plain text, formatted list)
- Calculate more complex derived values (BMI, retirement countdown, etc.)
- Add more conditional logic (different messages based on age ranges, experience levels)
- Include constants for configuration values (like retirement age, working days per year)
Submission
Create a single PHP file (like personal_card.php
) that runs without errors and displays your formatted personal information card. The file should be well-commented and use proper PHP syntax throughout.
Test your script by running it in a web browser or command line. Make sure all your data displays correctly and any calculations produce reasonable results.
Assessment Criteria
Your project will be evaluated on:
- Correctness: Does the script run without errors and display all required information?
- Data Type Usage: Are all five basic data types properly demonstrated?
- Code Quality: Are variables named clearly and code structured logically?
- Output Formatting: Is the final display readable and professional-looking?
- Calculations: Do any derived values calculate correctly?
- Requirements: Are all specified elements included?
Remember, this project isn't about creating the most complex or feature-rich application. It's about demonstrating solid understanding of PHP's basic data types and variable handling. Focus on clean, working code that clearly shows your grasp of these fundamental concepts.
Take your time, test frequently, and don't hesitate to experiment with different approaches. The goal is learning, not perfection.
← Previous Lesson: Type Declarations Next Lesson: Input and Output →