Skip to content

Commit

Permalink
Explain new PHP handling of non-numeric values by sum() and avg()
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Feb 13, 2024
1 parent 83bf2fc commit 6fd8ceb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ public function at( int $pos )
* The first line will return "3", the second and third one "2", the forth
* one "30" and the last one "40".
*
* NULL values are treated as 0, non-numeric values will generate an error.
*
* This does also work for multi-dimensional arrays by passing the keys
* of the arrays separated by the delimiter ("/" by default), e.g. "key1/key2/key3"
* to get "val" from ['key1' => ['key2' => ['key3' => 'val']]]. The same applies to
Expand Down Expand Up @@ -4661,6 +4663,8 @@ public function suffix( $suffix, int $depth = null ) : self
* The first line will return "9", the second one "6", the third one "90"
* and the last one "80".
*
* NULL values are treated as 0, non-numeric values will generate an error.
*
* This does also work for multi-dimensional arrays by passing the keys
* of the arrays separated by the delimiter ("/" by default), e.g. "key1/key2/key3"
* to get "val" from ['key1' => ['key2' => ['key3' => 'val']]]. The same applies to
Expand Down
4 changes: 2 additions & 2 deletions tests/MapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function testAvg()
{
$this->assertSame( 3.0, Map::from( [1, 3, 5] )->avg() );
$this->assertSame( 2.0, Map::from( [1, null, 5] )->avg() );
$this->assertSame( 2.0, Map::from( [1, 'sum', 5] )->avg() );
$this->assertSame( 2.0, Map::from( [1, 0.0, 5] )->avg() );
}


Expand Down Expand Up @@ -3070,7 +3070,7 @@ public function testSuffix()
public function testSum()
{
$this->assertSame( 9.0, Map::from( [1, 3, 5] )->sum() );
$this->assertSame( 6.0, Map::from( [1, 'sum', 5] )->sum() );
$this->assertSame( 6.0, Map::from( [1, 0.0, 5] )->sum() );
}


Expand Down

0 comments on commit 6fd8ceb

Please sign in to comment.