在休息了很久之后重新回到了php,需要一些幫助。我的函式正在回傳以下陣列。 我現在想獲得'id'和'name',并將它們回傳到自己的陣列中,其中name是鍵,id是值。 我應該怎么做呢?
object(stdClass)#11(1) {
["data"]=>
array(5) {
[0]=>
object(stdClass)#1 (3) {
["id"]=>
string(36) "7fd134a2-5f80-4d07-8a1a-a54c48f7e71b"
["type"]=>
string(13) "userattribute"。
["屬性"]=>
object(stdClass)#2 (1) {
["name"]=>
string(10) "Test1Test1"。
}
}
[1]=>
object(stdClass)#3 (3) {
["id"]=>
string(36) "dcdd87d5-1ff3-4fd9-8a75-7e20fe8f19d7" /span>
["type"]=>
string(13) "userattribute"。
["屬性"]=>
object(stdClass)#4 (1) {
["name"]=>
string(10) "Test1Test2"。
}
}
[2]=>
object(stdClass)#5 (3) {
["id"]=>
string(36) "b167b703-a63f-4548-9104-43a436871f45"
["type"]=>
string(13) "userattribute"。
["屬性"]=>
object(stdClass)#6 (1) {
["name"]=>
string(10) "Test1Test3"
}
}
[3]=>
object(stdClass)#7 (3) {
["id"]=>
string(36) "6a17046b-b665-493f-83be-35e0a9129c49"
["type"]=>
string(13) "userattribute"。
["屬性"]=>
object(stdClass)#8 (1) {
["name"]=>
string(10) "Test1Test4"。
}
}
[4]=>
object(stdClass)#9 (3) {
["id"]=>
string(36) "4704cf6f-1c8b-432e-88df-f6865c8690d5"
["type"]=>
string(13) "userattribute"。
["屬性"]=>
object(stdClass)#10 (1) {
["name"]=>
string(10) "Test1Test5"
}
}
}
}
uj5u.com熱心網友回復:
使用array_column()來提取每一列,并使用array_combine()來合并它們,以便一個是鍵,另一個是關聯陣列的值。
$result = array_combine(array_column($object-> data, 'id'), array_column($object-> data, 'name'))。
其中$object是持有你發布的資料的變數。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/331793.html
標籤:
