modelo_de_array_filter_multidimencional - 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: modelo_de_array_filter_multidimencional fullscreencopydownloadembedprint


Your result can be seen below.

Result of php executing





Full code of modelo_de_array_filter_multidimencional.php

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