使用相同参数时爆炸是否等同于内爆?(Is explode equivalent to implode when using the same parameter?)

系统教程 行业动态 更新时间:2024-06-14 17:02:17
使用相同参数时爆炸是否等同于内爆?(Is explode equivalent to implode when using the same parameter?)

假设我有以下功能:

public function normalize($string) { $substrings = explode(",", $string); return implode(",", $substrings); }

Will ($string == normalize($string))总是如此? 有什么特别的情况我应该考虑吗?

Let's say I have the following function:

public function normalize($string) { $substrings = explode(",", $string); return implode(",", $substrings); }

Will ($string == normalize($string)) always be true? is there any special case I should consider?

最满意答案

如果$ string是一个字符串,是的。

否则可能会发生类型转换:

implode(",", explode(",", 0))

这将导致“0”因此$string !== normalize($string)但$string == normalize($string)仍然成立。

If $string is a string, yes.

Otherwise type conversion may occur:

implode(",", explode(",", 0))

This will result in "0" thus $string !== normalize($string) but $string == normalize($string) still holds true.

更多推荐

本文发布于:2023-04-21 18:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/80166583552472bb4d62c0ccb802f5de.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   explode   equivalent   implode   parameter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!