3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Student { public $studentnummer; public $voornaam; } $apiResult = [ 'firstName' => 'Barry', 'sid' => 'S123', ]; $map = [ 'firstName' => 'voornaam', 'sid' => 'studentnummer', ]; $student = new Student; foreach ($apiResult as $key => $value) { if (isset($map[$key])) { $student->{$map[$key]} = $value; } } print_r($student);

preferences:
27.87 ms | 404 KiB | 5 Q