Question: Having trouble with this. I want to reference the post superglobal using a key which is generated by the concatenation of a string literal and a string variable.

```
$guests = array();
$guest_data = $this->compile_guests_for_hcp('g1');
array_push($guests, $guest_data($hcp_id));

function compile_guests_for_hcp($guest_identfier){
    return function($hcp_id) use ($guest_identfier){
        $guest = array(
            'fname' => $_POST["fname_$guest_identifier"],
            'lname' => $_POST["lname_$guest_identifier"],
            'city' => $_POST["city_$guest_identifier"],
            'state' => $_POST["state_$guest_identifier"],
            'degree' => $_POST["degree_$guest_identifier"],
            'zip' => $_POST["zip_$guest_identifier"],
            'specialty' => $_POST["specialty_$guest_identifier"],
            'email' => $_POST["email_$guest_identifier"],
            'phone' => $_POST["pref_phone_$guest_identifier"],
            'job_title' => $_POST["job_title_$guest_identifier"],
            'office_addr_line_1' => $_POST["office_addr_line_1_$guest_identifier"],
            'office_addr_line_2' => $_POST["office_addr_line_2_$guest_identifier"],
            'hcp_data_idhcp_data' => $hcp_id
        );
        return $guest;
    };
}

```

PHP is throwing undefined variable errors as it's trying to reference for example `$_POST["fname_"]` and `$_POST["guest_identifier"]`

I'm trying to access $\_POST["fname\_g1"] etc.

Answer: 
I'm thinking that your approach is a bit overly complicated, but your issue is not in the array index concatenation: there are no syntax errors in your code as you've presented it.

For example, this works like a charm:

```
$a = array("foo"=>1); 
$o = "o"; 
print $a["fo$o"]; // prints 1

```

Your issue is that the `$guest_identifier` value is not being set properly so you are looking for POST indexes which simply aren't there.

There are a few different ways around this. My first suggestion would be to simply verify that the ID is there to begin with before calling this function. If that is not an option, then I would probably create a helper:

```
function ifInPost($val, $default = NULL){
    if( isset( $_POST[ $val ] ) ) return $_POST[ $val ];
    return $default;
}

```

Then, you could simply replace the `$_POST["fname_$guest_identifier"]` with `ifInPost("fname_$guest_identifier")`
Replace all calls to `$_POST[...` with `@$_POST[...` to repress the errors.

Or check the value before using it like `isset($_POST[...]) ? $_POST[...]` ...

Or suppress PHP warnings by calling [error\_reporting(E\_ALL ^ E\_NOTICE)](http://php.net/manual/en/function.error-reporting.php)