fork download
  1. <?php
  2. class Thing
  3. {
  4. public $id;
  5. public $job_number;
  6. public $part_number;
  7.  
  8. public function __construct(Array $part) {
  9. $this->id = $part['id'];
  10. $this->job_number = $part['job_number'];
  11. $this->part_number = $part['part_number'];
  12. }
  13. }
  14.  
  15. $items = [
  16. [
  17. 'id'=> 1,
  18. 'job_number' => 'a1',
  19. 'part_number' => 'asde3'
  20. ],
  21. [
  22. 'id'=> 2,
  23. 'job_number' => 'b21',
  24. 'part_number' => 'vcse45'],
  25. [
  26. 'id'=> 45,
  27. 'job_number' => 'q8',
  28. 'part_number' => '101POP'],
  29. ];
  30.  
  31. $objects = [];
  32. foreach($items as $item){
  33. array_push($objects, new Thing($item));
  34. }
  35.  
  36. print_r($objects);
Success #stdin #stdout 0.02s 24556KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Thing Object
        (
            [id] => 1
            [job_number] => a1
            [part_number] => asde3
        )

    [1] => Thing Object
        (
            [id] => 2
            [job_number] => b21
            [part_number] => vcse45
        )

    [2] => Thing Object
        (
            [id] => 45
            [job_number] => q8
            [part_number] => 101POP
        )

)