Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions classes/Leth/IPAddress/IP/NetworkAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,18 @@ public function getIterator()
return new NetworkAddressIterator($this);
}

/**
* Get array of addresses in this network
*
* Warning: May use a lot of memory if used with large networks.
* Consider using an iterator and the count() method instead.
* @return array
*/
public function toArray()
{
return iterator_to_array($this, false);
}

/**
* Get count addresses in this network
* Implement \Countable
Expand Down
1 change: 1 addition & 0 deletions tests/IPv4NetworkAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public function testIteratorInterface()
$actual[] = (string)$ip;
}
$this->assertEquals($expected, $actual);
$this->assertEquals($expected, array_map('strval', $block->toArray()));
}

public function testTwoIterators()
Expand Down