Source Code:
(back to article)
<?php // Define an array of objects $arrayOfObjects = [(object) ["name" => "John", "age" => 30], (object) ["name" => "Jane", "age" => 25]]; // Define a function with a type hint for the parameter "arrayOfObjects" function someFunction(array $arrayOfObjects) { // Iterate over the array of objects foreach ($arrayOfObjects as $object) { // Output the name and age of each object echo "Name: " . $object->name . ", Age: " . $object->age . "\n"; } } // Call the function with the defined array of objects someFunction($arrayOfObjects); // Output: // Name: John, Age: 30 // Name: Jane, Age: 25
Result:
Report an issue