php - Convert CSV string to Array keys and a value of 1 or true -


Please help with finding a better solution for the code below.

Here's my existing solution:

$ list = '54, 78,3,5 '; $ List = explosion (",", $ list); Compare $ $ {$ v] = 1 as a foreign currency ($ k => $ v); }

When I run array_flip instead of foreach on the $ list, it returns an array like this:

  array (54 => 0 , 78 = & Gt; 1, ...)  

I need that another array which is already in this format can be compared with the IF statement: / P>

  Array (54 => 1, 78 => 1, ...)  

  $ list = '54, 78,3,5 '; $ List = explosion (",", $ list); $ Array = array_combine ($ list, array_fill (0, count ($ list), 1)); Print_r ($ array); Array ([54] => 1 [78] => 1 [3] => 1 [5] => 1)  

with all of it An array will create a value of $ list with the number at the same size as the 1 then a new array with values ​​of $ list And array_fill () ;

div>

Comments