使用file\u put\u contents file\u get\u contents-php上传和下载二维数组

使用file\u put\u contents file\u get\u contents-php上传和下载二维数组,php,Php,希望我不会长时间成为新手。我有一个二维数组(简化的),我正在尝试使用它。只需拉出、添加和上载文件记录。有人能原谅我的无知并解释我做错了什么吗 <?php // Updating Current Number of Vendors $vendorcount = @file_get_contents('../Keys/VendorCount/$v'); if(isset($vendorcount)) { $new_vendor_number = ($vendorcount + 1); $n =

希望我不会长时间成为新手。我有一个二维数组(简化的),我正在尝试使用它。只需拉出、添加和上载文件记录。有人能原谅我的无知并解释我做错了什么吗

<?php
// Updating Current Number of Vendors
$vendorcount = @file_get_contents('../Keys/VendorCount/$v');
if(isset($vendorcount))
{
$new_vendor_number = ($vendorcount + 1);
$n = $new_vendor_number;
}
else
{
$vendorcount = 0;
$new_vendor_number = 1;
$file = '../Keys/VendorCount/$v' ; 
file_put_contents($file, $vendorcount) ;
};

//getting record from file
$record = file_get_contents('../Vendors/$vendorlist');

//adding new information to record array
$record[$n] = array($new_vendor_number, $catname);

//uploading updated record
$file = '../Vendors/$vendorlist' ; 
file_put_contents($file, $record) ;
?>

为了将数组存储到文件或从文件还原数组,需要使用和。像这样:

$array = array(1,2,3);

// writing to file
file_put_contents('file.txt', serialize($array));

// restoring from file
$array = unserialize(file_get_contents('file.txt'));

这将适用于任何维度的数组。

我们需要更多详细信息。您的阵列是什么样子的?这里有什么问题?此代码做什么/不做什么?对于测试,请尝试以下操作:
$a='test';echo‘变量a为$a’;echo“变量a为$a”除了没有序列化之外,我的问题可能还在于没有正确定义数组。使用上面的示例:$record=array(array($new_vendor_number,$catname));用我的简单例子试试看,然后一步一步地改进到你的解决方案。然后您将看到代码中的哪一步是错误的。