时间:2021-07-01 10:21:17 帮助过:11人阅读
$obj = new stdClass();
$obj->userName = 'cheng';
$arr = array($obj);
echo $arr[0]->userName;
$obj1 = new stdClass();
$obj1->userName = 'cheng';
$obj = new stdClass();
$obj->did = 1;
$obj->comment = array('user_id'=>4,'userName'=>array($obj1));
$arr = array($obj);
echo $arr[0]->comment['userName'][0]->userName;
$obj1 = new stdClass();
$obj1->userName = 'cheng';
$obj = new stdClass();
$obj->did = 1;
$obj->comment = array('user_id'=>4,'userName'=>array($obj1));
$arr = array($obj);
$result = json_decode(json_encode($arr), true);
print_r($result);
Array
(
[0] => Array
(
[did] => 1
[comment] => Array
(
[user_id] => 4
[userName] => Array
(
[0] => Array
(
[userName] => cheng
)
)
)
)
)