Category: Sadness
Just read a comment in the PHP documentation and had another PHP madness moment.It seems you have to be really, really careful when comparing strings that include numbers… Command \ PHP Version7.0.0 – 7.1.35.4.4 – 5.6.305.2.1 – 5.4.3var_dump(‘123’ == ‘ 123’);TRUETRUETRUEvar_dump(‘1e3’ == ‘1000’);TRUETRUETRUEvar_dump(‘+74951112233’ == ‘74951112233’);TRUETRUETRUEvar_dump(‘00000020’ == … Read more »
What would you expect for this script to output?error_reporting(E_ALL); ini_set('display_errors',1);$text = "abc";var_dump(isset($text['key']));var_dump((bool) $text['key']);Maybe a notice? maybe some false there..But if you have in mind PHP logic.. you surely know..So, $text is a string and string characters can be accessed with $text[1] this is “b”Then if … Read more »
If you iterate over an array with & you should unset the value variable after to not modify the array accidentally after.$array = array('a', 'b', 'c', 'd');foreach($array as $key=>&$value) { if ($key = 3) { // change d to x $value = 'x'; }}// this … Read more »
Working with echo or print is very easy in PHP.At the begining it might be harder to understand concatenations or operations order, but after you master them is really easy.But there are some cases where you wonder how does this work ?!?!What does this print?echo … Read more »