title: Symfony 4: Accessing Form Data without Nested For Loop
body: <p>I would like to access the entities submitted by a form without having to use a nested for loop. Currently, in order to access the entity objects I am doing the following:</p>
  
  <pre><code>$courses = $form-&gt;getData();
  
  foreach ($courses as $course) {
      foreach ($course as $c) {
          //do logic on entity $c
      }
  }
  </code></pre>
  
  <p>Form builder class:</p>
  
  <pre><code>public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add('courses', EntityType::class, [
              'class' =&gt; Course::class,
              'choice_label' =&gt; 'name',
              'multiple' =&gt; true,
              'expanded' =&gt; true,
              'required' =&gt; false,
              'query_builder' =&gt; function (EntityRepository $er) use ($organization) {
                  return $er-&gt;createQueryBuilder('course')
                      -&gt;orderBy('course.semester', 'ASC');
              },
          ]);
      }
  </code></pre>
  
  <p>How can I structure the form such that the entities would be accessible with a single for loop?</p>