Skip to content
Discussion options

You must be logged in to vote

To solve this problem, we can follow these steps:

  1. Combine Names and Heights: Create a combined array of pairs where each pair consists of a name and its corresponding height.
  2. Sort the Combined Array: Sort the combined array based on heights in descending order.
  3. Extract Sorted Names: Extract the names from the sorted combined array.

Let's implement this solution in PHP: 2418. Sort the People

<?php
// Example usage:
$names = ["Mary","John","Emma"];
$heights = [180,165,170];
$result = sortPeople($names, $heights);

echo implode(",", $result); // Output: Mary,Emma,John
?>

Explanation:

  1. Combining Names and Heights:

    • We create an array called $combined where each element is a pair of a name …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
1 participant