php - How to fill the array values with the key values?
Get the solution ↓↓↓I have a form with 2 elements:
- checkboxes to select roles among a list
- a radio button to reverse the conditions
Depending if the radio button is opt-in, I am getting the roles array, that will be used to generate some sql:
$user_roles = array_filter($config->get('purge_users_roles'));
if($config->get('reverse_role_purge_condition') == 1){
$user_roles = array_filter($config->get('purge_users_roles'), function($x) {
return $x === 0;
});
foreach ($user_roles as $key => $value){
$user_roles[$key]=$key;
var_dump($user_roles);
}
}
I'm usingvar_dump
to display the unselected values:
array (size=2) 'membre_du_site' => int 0 'admin_site' => int 0
when in the other case, that would be somthg like :
array (size=2) 'membre_du_site' => 'membre_du_site' 'admin_site' => 'admin_site'
What is the best way to fill all array values with the corresponding key values, to get the same array structure in both cases?
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: composer detected issues in your platform: your composer dependencies require a php version ">= 8.0.2".
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.