如何反转数组
您好,我有一个字符串数组,我需要将它们从最后一个字符串输出到第一个字符串。
我没有看到 arrayReverse()
函数,但我刚刚学习 ColdFusion
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您好,我有一个字符串数组,我需要将它们从最后一个字符串输出到第一个字符串。
我没有看到 arrayReverse()
函数,但我刚刚学习 ColdFusion
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
你可以反向循环数组,
我认为你需要使用Java方法来真正反转数组。
You can just loop over the array in reverse
I think you need to use Java methods to really reverse the array.
仅供参考 CF 中的数组只是一个 ArrayList ,所以...
我不会费心去写
arrayReverse()
因为数组是在 CF 中按值传递的(直到 CF2016 的this.passArraybyReference
)所以它超级效率低下。FYI array in CF is just an ArrayList, so...
And I would not bother writing
arrayReverse()
because array is passed by value in CF (not until CF2016'sthis.passArraybyReference
) so it's super inefficient.我写了这个函数来反转数组。它修改数组并返回它。
我已经测试过它,它适用于字符串数组以及对象等。
我将它放入它自己的组件中,因此更容易在不同的项目中使用。
I wrote this function to reverse an array. It modifies the array and returns it.
I've tested it, and it works on arrays of strings, as well as objects, etc.
I put it into it's own component, so it's easier to use in different projects.
哦,但是有一个 ArraySort 方法!
ArraySort( array, sort_type [, sort_order] );
返回布尔值。
array
通过引用进行更新。sort_type
可以是numeric
、text
或textnocase
sort_order
可以是asc
或desc
请查看此处的文档:
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-ab/arraysort.html
Oh but there is an ArraySort method!
ArraySort( array, sort_type [, sort_order] );
Returns boolean.
array
is updated by reference.sort_type
can benumeric
,text
ortextnocase
sort_order
can beasc
ordesc
Check out the documentation here:
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-a-b/arraysort.html
会成功的。
Will do the trick.