Challenge: Filtering Users in Social Network Data with PHP 8

A hands-on exercise to test your knowledge of the new PHP 8’s functional additions.

We'll cover the following

This challenge will extensively test your understanding of the new PHP 8’s functional additions. We will use these concepts to retrieve the data using the new PHP 8’s functions.

Task

Use the User class and its callable functions to fulfill the following:

  • Question 1: Use the nullsafe and nested ternary operators to get the first friend of the first user.

  • Question 2: Use the arrow function and the str_starts_with() method to get all users whose email starts with “{Any friend name}.”

  • Question 3: Use the arrow function and the str_contains() method to get all users who have a friend named “Bob.”

  • Question 4: Use the arrow function and the str_replace() method to create a comma-separated list of friends for each user.

Coding playground

Attempt the challenge in the coding playground below.

Note: The starter code for the challenge has already been provided inside the code widget below.

Get hands-on with 1200+ tech skills courses.