将stdClass对象转换为php中的关联数组

Pon*_*ato 5 php arrays stdclass

我需要转换这个数组

Array ( 
[0] => stdClass Object 
     ( [title] => primo ) 
[1] => stdClass Object 
     ( [title] => secondo )) 
Run Code Online (Sandbox Code Playgroud)

Array ( 
[primo] => primo
[secondo] => secondo ) 
Run Code Online (Sandbox Code Playgroud)

尝试了不同的选项,包括类型转换,仍然没有找到正确的解决方案

Pup*_*pil 11

使用json_encode()json_decode()

$arr = json_decode(json_encode($yourObject), TRUE);
Run Code Online (Sandbox Code Playgroud)

json_decode()的第二个参数设置为TRUE.

功能定义:

mixed json_decode(string $ json [,bool $ assoc = false [,int $ depth> = 512 [,int $ options = 0]]])

这会将您的对象转换为关联数组.