kreut Posted February 18, 2011 Share Posted February 18, 2011 Hello, I have an array, $solutions, and a separate indexing array, $solution_order. From the $solution_order array (developed from the $order variable, where each $order variable looks like '0321' or '3021'), I'd like to create a new array $ordered_solutions, which indexes on the values picked from the $solution_order array. For example, if my $solutions array is (Big, Small, Fat, Skinny) and my $solution_order array is (2,3,1,0), then the final results should be (Fat, Skinny, Small, Big). I've written down what I have so far. Any thoughts about how to move this forward would be appreciated. Thanks! function GetOrder($solution, $wrong1, $wrong2, $wrong3, $order) { $solutions = array( $solution, $wrong1, $wrong2, $wrong3); $solution_order = array(substr($order,0,1), substr($order,1,1), substr($order,2,1), substr($order,3,1)); $ordered_solutions = array(); //what do to here?? return $ordered_solutions; } Quote Link to comment Share on other sites More sharing options...
requinix Posted February 18, 2011 Share Posted February 18, 2011 There's a function for that. function GetOrder($solution, $wrong1, $wrong2, $wrong3, $order) { $ordered = array_combine(str_split($order), array($solution, $wrong1, $wrong2, $wrong3)); ksort($ordered); // optional. depends on your code return $ordered; } Quote Link to comment Share on other sites More sharing options...
kreut Posted February 18, 2011 Author Share Posted February 18, 2011 Very clear solution! Thank you (and thanks PHP).... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.