public function toArray(int $mode = self::ARRAY_ASSOC): array
    {
        switch ($mode) {
            case self::ARRAY_MULTI_PART:
                $caseHelper = CaseHelperFactory::make(CaseHelperFactory::INPUT_TYPE_CAMEL_CASE);
                $keyVals = $this->toArray(self::ARRAY_ASSOC);
                $multiPart = [];

                foreach ($keyVals as $key => $val) {
                    $multiPart[] = ['name' => $caseHelper->toSnakeCase($key), 'contents' => "$val"];
                }

                $array = $multiPart;
                break;
            default:
                $array = array_filter((array)$this); // removes empty values
                break;
        }

        return $array;
    }
public function toArray(int $mode = self::ARRAY_ASSOC): array
    {
        switch ($mode) {
            case self::ARRAY_MULTI_PART:
                $caseHelper = CaseHelperFactory::make(CaseHelperFactory::INPUT_TYPE_CAMEL_CASE);
                $keyVals = $this->toArray(self::ARRAY_ASSOC);
                $multiPart = [];

                foreach ($keyVals as $key => $val) {
                    $multiPart[] = ['name' => $caseHelper->toSnakeCase($key), 'contents' => "$val"];
                }

                $array = $multiPart;
                break;
            default:
                $array = array_filter((array)$this); // removes empty values
                break;
        }

        return $array;
    }
public function toArray ( int $ mode = self :: ARRAY_ASSOC ) : array { switch ( $ mode ) { case self :: ARRAY_MULTI_PART : $ caseHelper = CaseHelperFactory :: make ( CaseHelperFactory :: INPUT_TYPE_CAMEL_CASE ) ; $ keyVals = $ this -> toArray ( self :: ARRAY_ASSOC ) ; $ multiPart = [ ] ; foreach ( $ keyVals as $ key => $ val ) { $ multiPart [ ] = [ 'name' => $ caseHelper -> toSnakeCase ( $ key ) , 'contents' => "$val" ] ; } $ array = $ multiPart ; break ; default : $ array = array_filter ( ( array ) $ this ) ; // removes empty values break ; } return $ array ; }
Return instance as array

@param int $mode Array mode

@return array
@throws \Exception
Return instance as array