0

I read file (answers.txt) and write values into an array

$filename = 'answers.txt';
$file = file($filename);

How I can add keys to the array? answers.txt looks like:

212
150
200
212

I need to get keys like:

$array =  array (
                  "first" => "212",
                  "second" => "150",
                  "third" => "200",
                  "four" => "212"
                );
Dimag Kharab
  • 4,439
  • 1
  • 24
  • 45

1 Answers1

1

Hope you are looking for this

 $keys=array("first","second","third","four");

 $values=array(212,150,200,212);

 $array_combine=array_combine($keys,$values);

 print_r($array_combine);