我读取文件(answers.txt
)并将值写入数组
$filename = 'answers.txt';
$file = file($filename);
如何向数组添加密钥? answers.txt
看起来像:
212
150
200
212
我需要获得以下密钥:
$array = array (
"first" => "212",
"second" => "150",
"third" => "200",
"four" => "212"
);
答案 0 :(得分:1)
希望你正在寻找这个
$keys=array("first","second","third","four");
$values=array(212,150,200,212);
$array_combine=array_combine($keys,$values);
print_r($array_combine);