Consider the following case. We have an array with identical keys.
$arr = array(1 => 10, 1 => 11);
What happens when the interpreter reaches this line of code? This is not a syntax error and it is completely valid. Very similar, but more interesting case is when we have an array of identical keys, where those identical keys are represented once as an integer and then as a string.
Yet another thing that’s great in PHP is the power you have when doing some string manipulation/operation. Here’s something that is really useful, but I think it remains a bit unknown. Let’s imagine you need to take the first (or whatever) character of a string. Most developers go to the obvious:
This code chunk return the first character of $str, but it can be used with the same success for any other character of the string. In my opinion this is more cleaner and its really syntactically self documented.
This approach can be useful when trying to check whether the first symbol for instance is “?” or “/”.
PHP is really full of functions for everything! Most of the time when you try to do something with strings, there’s a function that can do it better and faster.
The Route from $_GET to String
The global arrays in PHP contain request parameters. Either GET or POST. As you know if the page address is something like:
This means that you pass to the index.php file two parameters – “a” and “key” with their values: “b” and “value”. Now in this case you can dump the $_GET global array somewhere in index.php and you’ll receive something like this.