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' => 75, 'price' => 'Бесценен']
  7. ];
  8.  
  9. function findByName($warehouse, $name){
  10. foreach($warehouse as $wares){
  11. if ($wares['name'] == $name){
  12. return $wares;
  13. };
  14.  
  15. }
  16. }
  17.  
  18. $name = 'лук';
  19. $name = findByName($warehouse, $name);
  20. print_r ($name);
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
Array
(
    [name] => лук
    [weight] => 16
    [price] => 215
)