Page 1 of 1

Array to String conversion..Need Help

Posted: Tue Sep 27, 2016 12:04 pm
by joinnavdev
Hi All,

I am new to php & got struck with below notice/warning i.e. array to string conversion. Please find the below code, any help or suggestion in resolving the notice/warning would be great help........

I knew we can suppress the warning but want a solution the below notice/warning...

::::::CODE::::::

Code: Select all

$arrUrl=array();										
foreach($_GET as $k=>$v)
{																						
if($k=="attachmentID") continue;
if($k=="m")
{
$k="return_m";
}
else if($k=="a")
{
$k="return_a";
}
$arrUrl[]="{$k}={$v}";
}                                        
$url=implode("&",$arrUrl);


Notice: Array to string conversion at line $arrUrl[]="{$k}={$v}";

Thanks,
Nick

Re: Array to String conversion..Need Help

Posted: Tue Sep 27, 2016 12:52 pm
by requinix
One of those two variables is an array. I won't tell you which one. To fix the problem you should... well, I would say you should ditch the entire thing and do

Code: Select all

$qs = $_GET;
if (isset($qs["attachmentID"])) {
	unset($qs["attachmentID"]);
}
if (isset($qs["m"])) {
	$qs["return_m"] = $qs["m"];
	unset($qs["m"]);
}
if (isset($qs["a"])) {
	$qs["return_a"] = $qs["a"];
	unset($qs["a"]);
}
$url = http_build_query($qs);
instead because using a loop to do this is silly.

Re: Array to String conversion..Need Help

Posted: Thu Sep 29, 2016 4:31 pm
by joinnavdev
HI,

First of all really thanks for your help in resolving the issue.

Your modified code really helped a lot but got struck further with same issue....

http://www.rhats.com/index.php?m=search ... SearchOn=0


Trying to extract bulk_resume parameter but getting array to string.....

$bulk_resume_url="";
if(isset($GET["bulk_resume"]))
{
$bulk_resume_url="&bulk_resume=".$_GET["bulk_resume"];
}

One more time again your help will be highly appreciated. I knew this might be basic for a guy like me who is new to php is tough one to crack it....Hope you understand ....

Thanks,
nick

Re: Array to String conversion..Need Help

Posted: Thu Sep 29, 2016 5:05 pm
by joinnavdev
Hi,
While using your earlier suggestion...special character being added...

$qs = $_GET;

if (isset($qs["attachmentID"])) {
unset($qs["attachmentID"]);
}
if (isset($qs["m"])) {
$qs["return_m"] = $qs["m"];
unset($qs["m"]);
}
if (isset($qs["a"])) {
$qs["return_a"] = $qs["a"];
unset($qs["a"]);
}
$url = http_build_query($qs);

bulk_resume%5B%5D=2 is being built instead of bulk_resume=2

Is there any function in php which removes special character...

Thanks,
Nick

Re: Array to String conversion..Need Help

Posted: Thu Sep 29, 2016 5:26 pm
by joinnavdev
Hi,

I am sorry for too many post but after research got to know new things and wanted to share the code because of which extra character is coming....

<input type="radio" name="bulk_resume[]" value="1" <?php echo ($checkedSearchOption == 1) ? "checked":"" ?> />
<input type="radio" name="bulk_resume[]" value="2" <?php echo ($checkedSearchOption == 2) ? "checked":"" ?> />
<input type="radio" name="bulk_resume[]" value="3" <?php echo ($checkedSearchOption == 3) ? "checked":"" ?> /> Search <b>OVERALL</b> Resume

As I amusing [] reserver character so %5B%5D is there anyway to remove from URL?????

Once again sorry for too many replies...

Thanks,
Nick

Re: Array to String conversion..Need Help

Posted: Thu Sep 29, 2016 10:48 pm
by requinix
Don't name it with the []s.