Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 作为数组的求值字符串_Php_Arrays_Eval - Fatal编程技术网

Php 作为数组的求值字符串

Php 作为数组的求值字符串,php,arrays,eval,Php,Arrays,Eval,我有一个.html文件,其中包含以下内容: array('1', '786286', '45626'); 这就是它所包含的全部内容 在我的代码中,我要计算此值,然后打印它: $code = file_get_contents('array.html'); $nums = eval($code); print_r($nums); 但是,它没有打印任何内容 任何帮助都将不胜感激。首先,不要使用eval()。这是一种邪恶的功能,应该像瘟疫一样避免 其次,它不起作用,因为您没有编写正确的PHP代码。

我有一个.html文件,其中包含以下内容:

array('1', '786286', '45626');
这就是它所包含的全部内容

在我的代码中,我要计算此值,然后打印它:

$code = file_get_contents('array.html');
$nums = eval($code);
print_r($nums);
但是,它没有打印任何内容


任何帮助都将不胜感激。

首先,不要使用
eval()
。这是一种邪恶的功能,应该像瘟疫一样避免

其次,它不起作用,因为您没有编写正确的PHP代码。您的eval所做的是一个包含以下内容的.php文件:

<?php
array(1,2,3)
因此数组被保留。这意味着你的评估应该更像:

$text = file_get_contents('...');
// option 1
eval("\$arr = $text");
      ^^^^^^^
print_r($arr);

// option 2
$foo = eval("return $text");
             ^^^^^^
print_r($foo);

首先,不要使用
eval()
。这是一种邪恶的功能,应该像瘟疫一样避免

其次,它不起作用,因为您没有编写正确的PHP代码。您的eval所做的是一个包含以下内容的.php文件:

<?php
array(1,2,3)
因此数组被保留。这意味着你的评估应该更像:

$text = file_get_contents('...');
// option 1
eval("\$arr = $text");
      ^^^^^^^
print_r($arr);

// option 2
$foo = eval("return $text");
             ^^^^^^
print_r($foo);

别担心,我是哑巴。我得把$code还给你。别担心,我是个笨蛋。我必须返回$code。