top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

php json decode with variables that contains dashes?

0 votes
434 views
{"general":{
 "round-corner":"0",
 "border-stroke":"2",
 "background-color":"#ffffff"
 }
}

I have this json string, I know that php variable names doesn't support dashes. So what to do in this case ?

posted Jun 25, 2014 by Rajneesh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You can use an array format like this. Hyphened keys will work.

<?php

$json = '{"general":{
 "round-corner":"0",
 "border-stroke":"2",
 "background-color":"#ffffff"
 }
}';

$array = json_decode($json, true);

echo $array['general']['border-stroke']; // prints 2

?>
answer Jun 27, 2014 by Vrije Mani Upadhyay
...