Format::to_array PHP Method

to_array() public method

Format data as an array
public to_array ( mixed | null $data = NULL ) : array
$data mixed | null Optional data to pass, so as to override the data passed to the constructor
return array Data parsed as an array; otherwise, an empty array
    public function to_array($data = NULL)
    {
        // If no data is passed as a parameter, then use the data passed
        // via the constructor
        if ($data === NULL && func_num_args() === 0) {
            $data = $this->_data;
        }
        // Cast as an array if not already
        if (is_array($data) === FALSE) {
            $data = (array) $data;
        }
        $array = [];
        foreach ((array) $data as $key => $value) {
            if (is_object($value) === TRUE || is_array($value) === TRUE) {
                $array[$key] = $this->to_array($value);
            } else {
                $array[$key] = $value;
            }
        }
        return $array;
    }