使用带有爆炸(完())不工作 [英] Using end() with explode() does not work

查看:182
本文介绍了使用带有爆炸(完())不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这将包含一个文件上传的名称,例如image.jpg文件的字符串。
我试图使用爆炸功能,但它返回一个错误爆炸()预计参数2为字符串数组中......鉴于

我试着找原因,并将其与使用是如何指示在PHP.Net但无济于事。

  $ upload_extension =结束(爆炸(,$ feature_icon)。);


解决方案

您不能使用 端() 像你,因为


  

端() - >参数¶数组。这个阵列被引用,因为它是由函数修改通过。这意味着你必须通过一个真正的变量,而不是一个函数返回一个数组,因为只有实际变量可以通过引用传递。


所以不喜欢

  $ feature_icon =image.jpg的;
$ upload_extension =爆炸(,$ feature_icon。);
$ upload_extension =结束($ upload_extension);
后续代码var_dump($ upload_extension);

直播结果

I have a string which will contain a file upload name, for example "image.jpg". I'm trying to use the explode function but it's returning an error "explode() expects parameter 2 to be string, array given in..."

I've tried looking for reasons why and comparing it to how use is instructed on PHP.Net but to no avail.

$upload_extension = end(explode(".", $feature_icon));

解决方案

you can not use end() like you are doing since

end() -> Parameters ¶ The array. This array is passed by reference because it is modified by the function. This means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference.

so do like

$feature_icon ="image.jpg";
$upload_extension =  explode(".", $feature_icon);
$upload_extension = end($upload_extension);
var_dump($upload_extension );

Live result

这篇关于使用带有爆炸(完())不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆