Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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_Image_Variables - Fatal编程技术网

php函数名中的变量

php函数名中的变量,php,image,variables,Php,Image,Variables,我想利用PHP内置的imagejpeg和imagepng函数。 我有一个变量$type,它定义了文件类型jpeg或png 我想要一个函数调用。大概是这样的: image.$type($image, null, 100); 但这不起作用。有什么想法吗?如果在var中使用完整的函数名,它应该可以工作 $func = "image".$type; $func($image,null,100); 小心:imagepng使用介于0-9(而不是0-100)之间的质量 为了完整性:您应该使用一种更可靠的方

我想利用PHP内置的
imagejpeg
imagepng
函数。 我有一个变量
$type
,它定义了文件类型jpeg或png

我想要一个函数调用。大概是这样的:

image.$type($image, null, 100);

但这不起作用。有什么想法吗?

如果在var中使用完整的函数名,它应该可以工作

$func = "image".$type;
$func($image,null,100);
小心
imagepng
使用介于0-9(而不是0-100)之间的质量

为了完整性:您应该使用一种更可靠的方法,使用OOP方法。
但是我不知道你的情况和密码。所以这只是一个注释。

您可能想看看[变量]。()