我正在搜索周围,但我还找不到任何东西
我在我的PHP代码中使用和API类似:
Array(
[randomName] => stdClass Object (
[id] => 412
[key] => NameKey
[name] => Name
[title] => some title
)
)
我需要一些帮助,如何获得[key],因为[randomName]它是开发人员使用的随机名称?
这有124个这样的值:
Array(
[randomName] => stdClass Object (
[id] => 412
[key] => NameKey1
[name] => Name 1
[title] => some title
)
[something] => stdClass Object (
[id] => 412
[key] => NameKey2
[name] => Name 2
[title] => some title
)
[othename] => stdClass Object (
[id] => 412
[key] => NameKey3
[name] => Name 3
[title] => some title
)
[otherthing] => stdClass Object (
[id] => 412
[key] => NameKey4
[name] => Name 4
[title] => some title
)
[somethingelse] => stdClass Object (
[id] => 412
[key] => NameKey5
[name] => Name 5
[title] => some title
)
)
我需要将所有[键]都放到数组中,但我不知道如何进入[randomName]。
任何人都知道吗?
答案 0 :(得分:1)
没有看到问题,但是,
随机名是数组中的键,对象中的键是一个属性,所以:
$newList = array();
foreach ($values as $ramdomName => $object) {
$newList[] = $object->key;
}