protected function generatePhp(int $fieldgroupId, bool $translate = true) : string
    {
        $strReplace = array(
            "  "      => "    ",
            "!!\'"    => "'",
            "'!!"     => "",
            "!!'"     => "",
            "array (" => "array(",
            " => \n" => " => "
        );

        $pregReplace = array(
            '/([\t\r\n]+?)array/'   => 'array',
            '/[0-9]+ => array/'     => 'array',
            '/=>(\s+)array\(/'       => '=> array('
        );

        $fieldgroup = $this->getFieldgroupParams($fieldgroupId, $translate);

        $code = var_export($fieldgroup, true);
        $code = str_replace(array_keys($strReplace), array_values($strReplace), $code);
        $code = preg_replace(array_keys($pregReplace), array_values($pregReplace), $code);

        $export = "<?php \n\r\n\rif (function_exists('acf_add_local_field_group')) {\n\r";
        $export .= "    acf_add_local_field_group({$code});";
        $export .= "\n\r}";

        acf_update_setting('l10n_var_export', false);

        return $export;
    }