如何将 stdClass 对象转换为数组

how to convert stdClass Object in to an array

我想获取 stdClass 对象的名称。

"Array
(
    [0] => stdClass Object
        (
            [id] => 179111965447818
            [name] => foot ball
        )

    [1] => stdClass Object
        (
            [id] => 103992339636529
            [name] => Cricket
        )

)

Wishes out put:

array("foot ball","Cricket")

尝试循环并创建一个新数组

$newarr = array();
foreach($arr as $v) {
 $newarr[] = $v->name;
}
print_r($newarr);

你的问题很难理解,你显然没有尝试过。无论如何,这就是答案。

$array = array();
foreach($obj as $item) {
    array_push($array, $item->name);
}

数据将在 $array.

$newArray=array();
foreach($array as $valArray){
 //$valArray  has all the value that you required and
 // $valArray['name'] is actually what you need
$newArray=$valArray['name'] ;
}

$newArray 有你需要的。

I tried this and it worked for me

$sports=array();
foreach($sport as $key=>$val){
     $sports[$key] =$val->name; 
}