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)