-
Notifications
You must be signed in to change notification settings - Fork 1
Pivot
Maxim Stupakov edited this page May 6, 2018
·
5 revisions
Operation also known as "pivot table".
Reshapes data based on column values. Uses unique values from specified groups and columns to form axes of the resulting data table.
Applied aggregates will be in cells of the resulting data table.
$sloth = Sloth::from($data)
->pivot('foo', 'bar', 'baz')
->count();
$sloth->print();
foo A B C D one 1 1 1 two 1 1 1 1
print_r($sloth->fetch());
Array ( [0] => Array ( [foo] => one [A] => 1 [B] => 2 [C] => 3 [D] => ) [1] => Array ( [foo] => two [A] => 4 [B] => 5 [C] => 6 [D] => 7 ) )
If operation is called without any agregates, then First agregate is applied by default.
$sloth = Sloth::from($data)
->pivot('foo', 'bar', 'baz');
$sloth->print();
foo A B C D one 1 2 3 two 4 5 6 7
print_r($sloth->fetch());
Array ( [0] => Array ( [foo] => one [A] => 1 [B] => 2 [C] => 3 [D] => ) [1] => Array ( [foo] => two [A] => 4 [B] => 5 [C] => 6 [D] => 7 ) )