implode(',', $a);
I want to attach the $q variable in front of the $a so like this
implode(',', $q.$a);
But that doesn`t work. How can i put 2 variables in a implode function?
$a is an array with domain names like "com, org" and $q is the text (string) you type in before the domain names will appear.
I get the following error:
invalid argument passed in line..
Whole code:
$a = ['nl','net','com','co'];
$q = $_REQUEST["q"];
$domain = explode(".", $q);
$ext = @$domain[1] ?: ' ';
if (empty($ext)) {
echo implode(',',$a);
} else if (in_array($ext, $a)) {
echo $q;
} else {
$r = [];
foreach ($a as $x) {
if (strstr($x, $ext)) {
$r[] = $x;
}
}
echo (count($r)) ? implode(',',$r) : implode(',',$a);
}
$aand$q? And what error do you get?$ais an array and$qis an other array?$_REQUEST["q"]is? Is it an array? Is it a string? What is the desired output because it's not clear? Please explain what you get (value of$aand$q) and what is the output you want.