Just take a look at this url, and you will know what I mean.
https://www.google.com/search?q=site%3Aphpjs.org&q=date
And when I go to that url, the search term in google's search bar is site:phpjs.org date
.
How does Google 'morph' the two parameters together, and how would one do it in PHP?
It will always use the last variable's value in the provided url. This is more of a standard way, and it isn't just Google that handles it this way. You can try it yourself by creating a page named
index.php
in your root directory. Then access the page viahttp://example.com/index.php?q=John&q=Billy
. Inside index.php add this:<?php echo $_GET['q']; ?>
.So what happens is that the last value is used, except that google strips the URL and concats the variables' values together. I hope it makes sense!
Instead of encoding the space, Google uses the same
q
variable to accomplish the same thing.Unfortunately, PHP doesn't have the built-in ability to do this, because successive occurrences of the same query string parameter will overwrite the first one, unless the
[]
suffix is used.You would need something like this:
Contents of
$params
:Alternatively, you can change the loop body to this:
That will change
$params
to:Which will make it easier to just do: