Extension of the field in the two-air mass in the cycle



  • There's a mass.

    $a1 = array('car1' => array('color' => 'black',
                                        'weight'=> '100'),
                 'car2' => array('color' => 'white',
                                        'weight'=> '200'));
    

    I don't know how to add a new field in the cycletype’to the masses 'car1and 'car2'with some meaning like ‘light’, ‘Goods’ accordingly.
    Only adding to the mass $a1
    Thank you.



  • foreach($a1 as &$car){
        $car['type'] = 'легковая';
    }
    

    Or if there's a separate collection of car category

    $carTypes = ['car1' => 'легковая', 'car2' => 'грузовая'];
    

    foreach($a1 as $name => &$car){
    $car['type'] = $carTypes[$name];
    }


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2