用逗号分隔字符串到密钥php的数组

I have a string

 $tailored_information="3, 5, 10, 13, 7, 6";

Now I have need to make an array like

$input_array = array("Id" => 3, "Id" => 5);

I am using this but not work cause i cant add key ID

explode(",", $tailored_information)

An array has to have unique keys. Also, you will now have spaces in your values

What you could do is explode by ", " and then take that array as your array straight away. If the key you want/need is always "Id" then it doesn't matter anyway.

As been told, you can't have array with the same key, because it is a hash table, which will override the "id" every time. I suggest you to use simply

explode(", ", $id_array);

or

explode(", ", $another_arr['id']);

like this you will group the data by id...

If you wish to go into some more complicated - you could create your own data structure, which will be non-unique array - where you will divide different values by key... this way the print version will be whatever you want...

<?php
$abc = "3, 5, 10, 13, 7, 6";
 $new_array = explode(',',$abc);
$new_id_array = array();
foreach($new_array as $key=>$val){;
    $new_id_array[$key]['id'] = $val;
}
print_r($new_id_array);
?>

you can not put same key in a array key. so for that you have to create a nested array.and that will solve ur problem and now you can have same array key, but in different arrays.OR

$abc = "3, 5, 10, 13, 7, 6";
$new_array = explode(',',$abc);
foreach($new_array as $key=>$val){
    $new_id_array['id_'.$key] = $val;
}