如何在php中创建一个函数,然后调用它

时间:2018-07-28 10:00:40

标签: php laravel

$applicantAttr = [
            'name' => 'Taylor Otwell',
            'email' => 'vaibhav@coloredcow.com',
            'phone' => '123321',
            'college' => 'Sample college',
            'graduation_year' => '2018',
            'course' => 'Test Course',
            'linkedin' => 'https://github.com/coloredcow/employee-portal',
            'resume' => 'https://github.com/coloredcow/employee-portal',
            'form_data' => [
                'data 1' => 'Sample content 1',
                'data 2' => 'Sample content 2',
            ],
            'job_title' => $job->title,
        ];

如何在php中实现此功能,然后调用它。创建函数后,请在另一个地方调用它。

1 个答案:

答案 0 :(得分:0)

在您的应用文件夹中的helpers.php文件中创建函数

function getCustomData()
{
    $applicantAttr = [
            'name' => 'Taylor Otwell',
            'email' => 'vaibhav@coloredcow.com',
            'phone' => '123321',
            'college' => 'Sample college',
            'graduation_year' => '2018',
            'course' => 'Test Course',
            'linkedin' => 'https://github.com/coloredcow/employee-portal',
            'resume' => 'https://github.com/coloredcow/employee-portal',
            'form_data' => [
                'data 1' => 'Sample content 1',
                'data 2' => 'Sample content 2',
            ],
            'job_title' => $job->title,
        ];
    return $applicantAttr;
}

并将此函数调用为:

getCustomData();

For more details