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:

Requirements

Your personal information card must include the following elements, each demonstrating specific data types:

String Data (3 different examples)

Integer Data (2 different examples)

Float Data (2 different examples)

Boolean Data (2 different examples)

Null Value (1 example)

Additional Requirements

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:

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:

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 →