What is the Ds\Set toArray() function in PHP?

Overview

The Ds\Set::toArray() function in PHP is used to convert a set into an array.

Syntax

The toArray() function can be declared as shown in the code snippet below:

public array Ds\Set::toArray( void )

Return value

The toArray() converts a set into an array and returns the array.

Example

Consider the code snippet below, which demonstrates the use of the toArray() function.

<?php
$objSet = new \Ds\Set([0, 2, 4, 6]);
// Corresponding array is
echo "Array is:\n";
print_r($objSet->toArray());
?>

Explanation

We declare a set objSet in line 3. We use the toArray() function in line 7 to convert objSet to an array.

Free Resources