Create array using variables in php

I would like to create array using variables like this; what is the best alternative since this will not work?

$dn = array(
     "countryName" => $country,
     "stateOrProvinceName" => $state,
     "localityName" => $city,
     "organizationName" => $company,
     "organizationalUnitName" => $department,
     "commonName" => $domain,
     "emailAddress" => $email

That way seems fine, what’s not working?

Yes, that seems fine, please expand on “will not work”.

the array is not populated with the values in these variables as if using variables is not allowed, but if you are sure it is allowed, I will continue looking for errors in my script. Thanks.

Is the array not populated but contains the keys? If so, are you sure your variables ($country, $email, etc) exist in the context you’re using them?

You are correct, this part of my code is working, and I have found my bug, thanks everyone!

1 Like