4

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?

Alfred
  • 73
  • 6

1 Answers1

5

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.

Máthé Endre-Botond
  • 4,826
  • 2
  • 29
  • 48