如何将var_export的输出读入PHP中的变量?

2022-08-30 20:25:28

输出如下,在输出.txt文件中恢复:

array (
  'IMType' => '1',
  'Email' => 'test@gmail.com',
  'SignupName' => 'test11',
  'Password' => '11111',
  'Encrypted' => '',
  'Confirm' => '11111',
  'OldPassword' => '',
  'Name' => 'test',
  'SignupProvinceText' => 'province',
  'SignupCity' => 'cityname',
  'Street' => 'street x.y',
  'SignupIndustry' => 'IT',
  'SignupCompany' => 'jobirn',
  'SignupJt' => 'engineer',
  'CellPhoneNum' => '',
  'linked_in' => '',
)

它实际上是的输出,但是如何再次将其读入变量?var_export(my_variable,true)


答案 1

喜欢这个:

$dumpStr = var_export($var,true);
eval('$somevar = ' . $dumpStr.';');

答案 2

也许你想序列化对象,然后取消序列化?http://php.net/serialize


推荐