1

I have a named array that look like this:

$arr = array('name'=>'somename','value'=>'somevalue');

I want to turn that array into something like this:

name='somename' value='somevalue'

I tried http_build_query() to do it.

echo http_build_query($arr, '', ' ');

But this is the result I get:

name=somename%21 value=somevalue%21

How can I get the result I want with http_build_query()? Or, is there any PHP function to do it?

Thank you.

0

3 Answers 3

0

http_build_query returns a urlencoded string. If you don't want that you can run it through urldecode

$arr = array('name'=>"'somename'",'value'=>"'somevalue'");
print urldecode(http_build_query($arr,null,' '));
Sign up to request clarification or add additional context in comments.

1 Comment

not return with single quote
0

Try with foreach()

$arr = array('name'=>'somename','value'=>'somevalue');
$str = '';
foreach($arr as $k=>$v) {
  $str.= "$k='$v' ";
}
echo $str;

Comments

0
foreach ($array as $key => $value) {
  $result .= "$key='$value' ";
}
echo rtrim($result,' ');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.