How to sort 1 array in Swift / Xcode and reorder multiple other arrays by the same keys changes

前端 未结 4 1922
北海茫月
北海茫月 2020-12-10 00:01

Sorry for the complex wording of the question. My main experience is with PHP and it has a command called array_multisort. The syntax is below:

bool array_mu         


        
4条回答
  •  醉梦人生
    2020-12-10 00:16

    I believe AlainT:s solution is to prefer, but to extend the variety of options, below follows a solution mimicking what a zip5 method could let us achive (in case we could use zip for zipping together 5 sequences instead of its limit of 2):

    /* example arrays */
    var firstName: [String] = ["David", "Paul", "Lisa"]
    var age: [Int] = [17, 27, 22]
    var city: [String] = ["London", "Rome", "New York"]
    var country: [String] = ["England", "Italy", "USA"]
    var active: [Int] = [906, 299, 5060]
    
    /* create an array of 5-tuples to hold the members of the arrays above.
       This is an approach somewhat mimicking a 5-tuple zip version.        */
    var quinTupleArr : [(String, Int, String, String, Int)] = []
    for i in 0..

提交回复
热议问题