Return The Group For The Largest - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.

Name: Return The Group For The Largest fullscreencopydownloadembedprint


Your result can be seen below.

Result of php executing





Full code of Return The Group For The Largest.php

  1. <?php
  2.  
  3. function returnTheGroupForTheLargest($value, $group) {
  4.     $result = array_filter($group, function($item) use ($value) {
  5.         return $item['value'] >= $value;
  6.     });
  7.     if ($result) $result = array_values($result)[0];
  8.     return $result;
  9. }
  10.  
  11. $foo = [
  12.     [
  13.         'id' => '1',
  14.         'value' => 1000,
  15.     ],
  16.     [
  17.         'id' => '2',
  18.         'value' => 2000,
  19.     ],
  20.     [
  21.         'id' => '3',
  22.         'value' => 3000,
  23.     ],
  24.     [
  25.         'id' => '4',
  26.         'value' => 4000,
  27.     ],
  28.     [
  29.         'id' => '5',
  30.         'value' => 5000,
  31.     ],
  32. ];
  33.  
  34. var_dump(returnTheGroupForTheLargest(1001, $foo));
File Description
  • Return The Group For The Largest
  • PHP Code
  • 13 Oct-2021
  • 611 Bytes
You can Share it: