How does strpos() function in PHP return int as well as boolean? -
this w3school says strpos() function :
returns position of first occurrence of string inside string, or false if string not found.
how function defined? possible write such functions returns values of 2 different datatypes in other languages well?
many dynamically typed languages allow return whatever want function. typed languages don't.
in php function can return anything wants, including booleans, ints, strings, null, arrays, kinds of objects, whatever need. it's same in example javascript , lua, dynamically typed.
just make sure check return type of function if can different kinds of things. things int(0) , false, considered equivalent if use == comparison. use === make sure it's right type.
Comments
Post a Comment