I wrote something like this:
private function addDefaultConfiguration(): void
{
$specialNameKeys = ['name1Id', 'name2Id', 'name3Id', 'name4Id'];
$specialAgeKeys = ['age1Id', 'age2Id', 'age3Id', 'age4Id'];
foreach ((new PersonStruct())->jsonSerialize() as $key => $value) {
if (in_array($key, $specialNameKeys)) {
$value = $this->getNameRandomId();
}
if (in_array($key, $specialAgeKeys)) {
$value = $this->getAgeRandomId();
}
}
}
but I'm sure this if can be written better. I'd love to use regex for this, but I have no idea how.
Aucun commentaire:
Enregistrer un commentaire