PHP Casting Variable as Object type in foreach Loop

前端 未结 5 561

Within the following code, $quiz_object->personalities contains an array of Personality objects.

// Loop through each personality th         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-01 15:50

    If you want actual type declarations in the code as opposed to comments that could be picked up differently depending on the IDE, you can use the array_* functions, for example array_walk.

    array_walk($quiz_object->personalities, function (Personality $p) {
        echo $existing_personality->GetQuizMakerPersonalityHTML();
    });
    

提交回复
热议问题