0
我想弄清楚如何檢查一個對象的存在,同時做一個for循環在樹枝。檢查樹枝中的for循環內是否存在對象
這就是我的代碼的樣子。
{% for topic in topics %}
{% set id = topic.id %}
{% set ratings = authRatings.id %}
{% if ratings is defined %}
{% else %}
{% endif %}
{% endfor %}
topic.id是針和authRatings是其topic_id命名的不同對象的草垛。如果一個對象匹配topic.id評級應該被定義。
object
(stdClass)[76]
public '24' =>
object
(stdClass)[77]
public 'topic_id' => string '24' (length=2)
public 'user_id' => string '2' (length=1)
public 'likes' => string '0' (length=1)
public 'dislikes' => string '1' (length=1)
public 'time' => string '1348927295' (length=10)
public '15' =>
object
(stdClass)[78]
public 'topic_id' => string '15' (length=2)
public 'user_id' => string '2' (length=1)
public 'likes' => string '1' (length=1)
public 'dislikes' => string '0' (length=1)
public 'time' => string '1348927363' (length=10)