Question: I have a dialog coded in php. On submit, I send the data back to the dialog to store via ajax (I don't want the dialog to close). This is mostly working but the format of the posted data isn't what I would like. Here is the ajax code

```
    $('#but1').click(function() {  
      var apply_to = $("input[name='group-apply']:checked").val();
      var el = document.getElementById('multi-selector');
      var selected = GetSelectValues(el);

      var data = [];
      data[0] = 'apply-to:'+ apply_to;
      data[1] = 'selected:' + selected;
      data = {data};         

       $.ajax({
            url : "example.php",
            type: "POST",
            data : data,
            success:function(result){
              $("#form-container").html(result);
            }
       });
    });   

```

When the above is ran, the php in the dialog displays this

```
    Array
    (
        [data] => Array
            (
                [0] => apply-to:Include
                [1] => selected:8,9,5,1
            )

    )

```

In order to use the above, I need to access it like this and then explode that to get the value. 

```
    $_POST['data'][0]

```

I would like the data to display like this

```
    Array
    ( 
        [0] => apply-to:Include
        [1] => selected:8,9,5,1
    ) 

```

or, ideally:

```
    Array
    ( 
        [apply-to] => Include
        [selected] => 8,9,5,1
    ) 

```

Would someone please explain how to do that, if possible?

Answer: 
> 
> but were should put the else
> 
> 
> 

It is not mandatory to follow `if` with `else`. The purpose of specifying `else` is to allow your code execution flow to go through all other case when `if` was not satisfied (true).

> 
> if i use this only the last if statement only works for the else
>  statement
> 
> 
> 

Because, `if` might have satisfied, so it executes `else` case. I would suggest to include `return` in each `if` case. So that, if any of the `if` case was satisfied. Then, it won't execute further code.
This should not be news to you: you are doing it wrong.

There are several ways to implement your desired solution,
here is one of them:

```
boolean performSave = true;

if (field1 is empty)
{
    do some stuff.
    performSave = false;
}

if (field2 is empty)
{
    do some stuff.
    performSave = false;
}

... repeat for any number of fields.

if (performSave) // no fields are empty.
{
    save stuff.
}

```