ovi.ro

ovi.ro

Category Archives: Sadness

A little bit of PHP sadness

Compare strings in PHP

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 Version 7.0.0 – 7.1.3 5.4.4 – 5.6.30 … Read more »

Strings array access issue

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 … Read more »

Foreach with reference

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 … Read more »

PHP echo print question

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 … Read more »