CalculatedColumn Process
This example shows the usage of CalculatedColumn process
name | hour_rate | working_hours |
John |
$20/hrs |
123 hrs |
Marry |
$30/hrs |
112 hrs |
Peter |
$25/hrs |
132 hrs |
Donald |
$40/hrs |
89 hrs |
->pipe(new CalculatedColumn(array(
"total"=>"{hour_rate}*{working_hours}",
"total_by_func"=>function($row){
return $row["hour_rate"]*$row["working_hours"];
}
)))
name | hour_rate | working_hours | total | total_by_func |
John |
$20/hrs |
123 hrs |
$2,460 |
$2,460 |
Marry |
$30/hrs |
112 hrs |
$3,360 |
$3,360 |
Peter |
$25/hrs |
132 hrs |
$3,300 |
$3,300 |
Donald |
$40/hrs |
89 hrs |
$3,560 |
$3,560 |
The example demonstrates usage of `CalculatedColumn` process. The CalculatedColumn process creates new column and use formula to create value. As you may see there are two ways to enter formula. You can define formular in string and wrapped field name in bracket `"{hour_rate}*{working_hours}"`. Second option, you can define your own custom function to calculate value as you see the `"total_by_func"` in above example.