Hi-Folks / array

Arr class is built on top of the PHP array functions. Arr exposes methods for creating, managing, accessing to the array data structure.
https://packagist.org/packages/hi-folks/array
MIT License
15 stars 9 forks source link

Add Table method: toArray() #53

Closed roberto-butti closed 1 year ago

roberto-butti commented 2 years ago

What

Add new method to Table class, in src/Table.php file

Description

The toArray() method returns a bidimensional PHP array from Table class.

In Table class, you could have something like this:

    /**
     * @return array
     */
    public function toArray(): array
    {
        $result = [];
        foreach ($this->rows() as $key => $row ) {
            $result[$key] = $row->arr();
        }
        return $result;
    }

Checklist

RoadSigns commented 2 years ago

I think personally for this we should not call it arr() since it implies that it's related to the Arr object. I think a more fitting name might be toArray().

We can then use this to cover the entire table and all of the Arr objects inside of it to an array based format.

We could even then look in the future to adding something like toJson() on the Table to get the information encoded.

roberto-butti commented 2 years ago

I think personally for this we should not call it arr() since it implies that it's related to the Arr object. I think a more fitting name might be toArray().

We can then use this to cover the entire table and all of the Arr objects inside of it to an array based format.

We could even then look in the future to adding something like toJson() on the Table to get the information encoded.

totally agree on the naming. I changed the title and the first comment of the issue.