문제

I have a black out since 1 hour ago. I working in CI and I have following array:

   Array
   (
    [0] => stdClass Object
        (
            [id] => 58
            [idAby] => 57
            [utilizator] => gigel@gigel.com
            [parola] => ########
            [group] => 3
            [nume] => Georgescu
            [confirm] => 1
        )

   )

In viewer, I'm simply loop array as follow :

 <?php foreach($arr as $key=>$value):?>
 <span id="<?=$value->id?>"><?= $value->nume ?></span>
 <?php endforeach ?>

But my question is if there is a simply way to return stdClass Object key ?

Thank you in advance.

도움이 되었습니까?

해결책

get_object_vars() is what you need. Combine with array_keys() and you have an array with all the properties.

http://en.php.net/get_object_vars

다른 팁

From what I understand, you would like to know the properties of an object. If that is correct, I would suggest looking at get_object_vars() in the php.net manual.

According to the manual:

Returns an associative array of defined object accessible non-static properties for the specified object in scope.

Example:

<?php 
$properties = get_object_vars($value); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top