Measurements can be added together using add() and subtracted
using sub(). The result will use the same type as the
originating object. Dynamic objects support a fluid style of programming, where complex
sequences of operations can be nested without risk of side-effects altering the input
objects.
Example 598. Adding units
<?php
// Define objects
$unit = new Zend_Measure_Length(200, Zend_Measure_Length::CENTIMETER);
$unit2 = new Zend_Measure_Length(1, Zend_Measure_Length::METER);
// Add $unit2 to $unit
$sum = $unit->add($unit2);
echo $sum; // outputs "300 cm"
Automatic conversion
Adding one object to another will automatically convert it to the correct unit. It
is not necessary to call convertTo()
before adding different units.
Example 599. Subtract
Subtraction of measurements works just like addition.
<?php
// Define objects
$unit = new Zend_Measure_Length(200, Zend_Measure_Length::CENTIMETER);
$unit2 = new Zend_Measure_Length(1, Zend_Measure_Length::METER);
// Subtract $unit2 from $unit
$sum = $unit->sub($unit2);
echo $sum;




