PHP 代码简洁之道(小结)(15)

好的:

function showList(array $employees): void
{
 foreach ($employees as $employee) {
  $expectedSalary = $employee->calculateExpectedSalary();
  $experience = $employee->getExperience();
  $githubLink = $employee->getGithubLink();
  $data = [
   $expectedSalary,
   $experience,
   $githubLink
  ];

  render($data);
 }
}

非常好:

最好让你的代码紧凑一点。

function showList(array $employees): void
{
 foreach ($employees as $employee) {
  render([
   $employee->calculateExpectedSalary(),
   $employee->getExperience(),
   $employee->getGithubLink()
  ]);
 }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持黑区网络。