fork download
  1. <?php
  2. $warehouse = [
  3. ['name' => 'картошка', 'weight' => 100, 'price' => 100500],
  4. ['name' => 'морковка', 'weight' => 50, 'price' => 5000],
  5. ['name' => 'лук' , 'weight' => 16, 'price' => 215],
  6. ['name' => 'оп' , 'weight' => 1, 'price' => 999999]
  7. ];
  8.  
  9.  
  10. $checkWeightIsLessThan100 = function ($item) {
  11. return $item['weight'] < 100;
  12. };
  13.  
  14. function findItems($warehouse, $checkWeightLessThan100){
  15. foreach ($warehouse as $item){
  16. if($checkWeightLessThan100){ //если вес меньше 100 то
  17. return $item; //как можно вернуть сразу несколько значений в виде массива?
  18. }
  19. }
  20. };
  21.  
  22. $warehouse = FindItems($warehouse, $checkWeightLessThan100 );
  23. var_dump ($warehouse);
Success #stdin #stdout #stderr 0.01s 82880KB
stdin
Standard input is empty
stdout
NULL
stderr
PHP Notice:  Undefined variable: checkWeightLessThan100 in /home/MbWu2R/prog.php on line 22