在PHP中更改关联数组索引的位置
I have an associative array in PHP. i want to change position of an array index and its value.
我在PHP中有一个关联数组。我想改变数组索引的位置及其值。
Array
(
[savedRows] => 1
[errors] => Array
(
[0] => System has Skipped this row, because you have enter not valid value "" for field "description" in sheat "Electronics Laptops" row number "4"
)
[success] => successfully saved.
)
to like this
喜欢这个
Array
( [savedRows] => 1 [success] => successfully saved. [errors] => Array ( [0] => System has Skipped this row, because you have enter not valid value "" for field "description" in sheat "Electronics Laptops" row number "4" ) )
([savedRows] => 1 [success] =>已成功保存。[errors] =>数组([0] =>系统已跳过此行,因为您输入了无效值“”字段“描述”在sheat中“电子笔记本电脑“行号”4“))
i want to change ["errors"] index position from second to last and [success] index position at second when ever this array build. This is a dynamic array not a static it builds when a function call on function return i am getting this array.
我希望改变[“errors”]索引位置从秒到最后和[成功]索引位置在第二次这个数组构建时。这是一个动态数组而不是静态它在函数调用函数返回时生成这个数组。
3 个解决方案
#1
3
You can use array functions, but by far the easiest way to change it would be:
您可以使用数组函数,但到目前为止,更改它的最简单方法是:
$newRow = ['savedRows' => $oldRow['savedRows'],
'success' => $oldRow['success'],
'errors' => $oldRow['errors']];
But it is an associative array, not a numeric array, so order should not be that important.
但它是一个关联数组,而不是数字数组,所以顺序不应该那么重要。
更多相关文章
- PHP-从多维数组中删除重复值
- PHP递归函数删除所有子节点导致stackoverflow
- 更改数组键而不更改顺序
- 如何在数组中存储产品数量
- php吧字符串直接转换成数组处理
- 使用 PHP usort() 通过用户自定义的比较函数对数组进行排序
- [开心学php100天]第五天:string函数(上)
- PHP print_r 转换/还原为数组
- curl获取网页内容出现乱码或为空的解决方案,另附curl_getinfo函数