-3

I want to get the names of stdClass Object.

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

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

)

Wishes out put:

array("foot ball","Cricket")

  • Possible duplicate of [Convert stdClass object to array in PHP](https://stackoverflow.com/questions/19495068/convert-stdclass-object-to-array-in-php) – mvladk Jun 20 '17 at 09:42

4 Answers4

2

I tried this and it worked for me

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

Your question is hard to understand, and you clearly haven't tried it. Here's the answer anyways champ.

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

The data will be in $array.

Darren
  • 12,786
  • 3
  • 34
  • 71
0

try a loop and create a new array

$newarr = array();
foreach($arr as $v) {
 $newarr[] = $v->name;
}
print_r($newarr);
Rakesh Sharma
  • 13,404
  • 4
  • 34
  • 41
0
$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 has what you require.

Danyal Sandeelo
  • 11,068
  • 6
  • 37
  • 64