英文:
How to access stdclass object in php
问题
如何从下面的代码中访问名称:
如何访问stdclass对象:
stdClass对象
(
[formdata] => [{"name":"aaa"},{"designation":"","organization":"","country":"","email":"","phone":"","status":"","interest":[],"comment":"","radio":""}]
)
英文:
Can anyone tell me how to access name from below code :
How to access stdclass object
stdClass Object
(
[formdata] => [{"name":"aaa"},{"designation":""},{"organization":""},{"country":""},{"email":""},{"phone":""},{"status":""},{"interest":[]},{"comment":""},{"radio":""}]
)
答案1
得分: 0
你可以像这样做
$obj = new stdClass();
$obj->formdata = [
["name" => "aaa"],
["designation" => ""],
["organization" => ""],
["country" => ""],
["email" => ""],
["phone" => ""],
["status" => ""],
["interest" => []],
["comment" => ""],
["radio" => ""]
];
$newdata = json_decode(json_encode($obj), true);
$data = json_decode($newdata['formdata'], true);
echo '<pre>'; print_r($data);
die;
这将给你一个数组,你可以访问每个变量。
英文:
you can do it like this
$obj = stdClass Object
(
[formdata] => [{"name":"aaa"},{"designation":""},{"organization":""},{"country":""},{"email":""},{"phone":""},{"status":""},{"interest":[]},{"comment":""},{"radio":""}]
)
$newdata = json_decode(json_encode($obj), True);
$data = json_decode($newdata['formdata'], True);
echo '<pre>';print_r($data);
die;
it will give you and array and you can access each variables
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论