douwen1549
2014-08-27 19:12
采纳率: 100%
浏览 24
已采纳

基于类似的数组对数组进行排序?

I have 2 arrays with numerical indices that have the same number of keys and similar but not identical values. $unordered has the unordered data, whereas array $ordered has the data in the proper order. I want to sort $unordered in the same order as $ordered, but keep the percentage values in square brackets from $unordered.

$unordered:

[0] => "Horse [1%]"
[1] => "Cat [5%]"
[2] => "Dog [94%]"

$ordered:

[0] => "Cat"
[1] => "Horse"
[2] => "Dog"

Thanks.

图片转代码服务由CSDN问答提供 功能建议

我有2个数组索引的数组具有相同数量的键和相似但不相同的值。 $ unordered具有无序数据,而array $ ordered具有正确顺序的数据。 我想按照与$ ordered相同的顺序排序$ unordered,但是将百分比值保存在$ unordered的方括号中。

$ unordered:

  [0] =>  “马[1%]”
 [1] =>  “猫[5%]”
 [2] =>  “Dog [94%]”
   
 
 

$ ordered:

  [0] =>  “猫”
 [1] =>  “马”
 [2] =>  “狗”
   
 
 

谢谢。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题