dqsot35145 2012-11-13 13:41
浏览 28
已采纳

foreach在具有匹配属性的对象数组上

I have an array of objects I'm using to create a menu, and each object has the properties id, video_id and chapter_id.

I'd like to make a for each loop such as

foreach($menu_objects as $object WHERE $object->chapter == $variable)

Is there a way of doing this?

  • 写回答

4条回答 默认 最新

  • dongqixuan3112 2012-11-13 13:44
    关注

    PHP doesn't offer syntax like that, however, you could always make it an if-statement as the first line in the loop:

    foreach ($menu_objects as $object) {
        if ($object->chapter != $variable) continue;
        ... process as normal ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?