Question: ```
<?php
                $i=0;
                if( $free_form_fields != '' ) :
                  foreach ($free_form_fields as $fields) 
                  {
                    $parameters = json_decode($fields->parameters);
                    // echo $i;
                    echo "{$form_field_order[$i]}";
                    // if($form_field_order[$i] == $fields->id)
                    // {  
                      echo "<li class='ui-state-default' id={$fields->id}>{$parameters->label}</li>";
                    // }
                    $i = $i+1;
                  } 
                endif;
              ?>

```

I want to check something like this `if($form_field_order[$i] == $fields->id)`

but it is giving me an error 

```
> Undefined offset: 2

```

so basically how can i access the $i th value (0,1...) of array $from\_field\_order? 

**Edit**

```
print_r($form_field_order);die(); gives an array

Array ( [0] => 2 [1] => 1 )

```

Answer: 
The array contains only two elements (0,1 indexed). It tries to access index 2 and throws this error as it is not existing. So Put a condition to check if the element exists using `isset($form_field_order[$i])` before accessing that
Try this,

```
<?php
                $i=0;
                if( count($free_form_fields) > 0 ) :
                  foreach ($free_form_fields as $fields) 
                  {
                    $parameters = json_decode($fields->parameters);
                    // echo $i;
                    echo $form_field_order[$i];
                    // if($form_field_order[$i] == $fields->id)
                    // {  
                      echo "<li class='ui-state-default' id={$fields->id}>{$parameters->label}</li>";
                    // }
                    $i = $i+1;
                  } 
                endif;
              ?>

```