How to check if a specific key array element exists?

I have my look in twing

and I have an array that has or hasnt the key value I need to check it if it exists?

example {{ weather.wind.deg }} , and at the moment it is possible there is no deg wind, so the weather.wind array will not contain the witch deg key element; how can I check if it is or not? maybe I should do it before I see it before my eyes? somewhere here?

 $app->get('/', function () use ($app) { return $app['twig']->render('index.html.twig', array( 'weather' => $app['weather_service']->get($app['location_service']->get()), 'location' => $app['location_service']->get()) ); }); 
+4
source share
1 answer

In the template you can do:

 {% if weather.wind.deg is defined %} make your things {% endif %} 
+7
source

Source: https://habr.com/ru/post/1501921/


All Articles