get_object_vars()
is what you need. Combine with array_keys()
and you have an array with all the properties.
CodeIgniter foreach loop. How to refer to object "key"
-
24-06-2022 - |
문제
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.
해결책
다른 팁
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);
제휴하지 않습니다 StackOverflow