我使用 aws redis 缓存来获得更快的结果,而不是保存在数据库中。 用这个方法
$result = $client->listTagsForResource([
'ResourceName' => '<string>', // REQUIRED
]);
现在它以给定的格式给出结果。
Array
(
[0] => Array
(
[Key] => key1
[Value] => string1
)
[1] => Array
(
[Key] => status
[Value] => 1
)
)
我无法在亚马逊文档中找到可以给我直接结果的函数,所以我决定在 array 中搜索,但是在带有循环的非常大的数组中查找会花费我的时间。那么有没有办法将其转换为以下内容
Array
(
[key1] => string1,
[status] => 1
)
所以我可以使用$array['key1']直接访问数组索引
最佳答案
您可以尝试这样的方法来创建新数组:
$newArray = array_combine(
array_column($array, 'Key'),
array_column($array, 'Value')
);
echo $newArray['status'];
关于php - 将大型数组转换为无循环的关联数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58716060/