Php Syntax Unexpected Sytax Error
I want to write like this in php. How can i express samely into php?
开发者_开发技巧$test = '{"longUrl": "http://www.yahoo.com"}';
Thanks.
If you want to write actual PHP code to make a new object (assuming your example is JSON), there's no literal/shortcut syntax in PHP for that; you have to make a new stdClass
object and set its variables manually:
$test = new stdClass;
$test->longUrl = "http://www.yahoo.com";
If you are comfortable writing JSON inside a string, as you are doing in your example, simply feed that into json_decode()
and you have yourself a stdClass
object:
$test = json_decode('{"longUrl": "http://www.yahoo.com"}');
$test = array("longUrl" => "http://www.yahoo.com");
>echo $test['longUrl']
http://www.yahoo.com
精彩评论