Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $table1_result = array(
- 0 => array('score' => 110, array('node_id'=>1, 'name'=>'apple')),
- 1 => array('score' => 89, array('node_id'=>2, 'name'=>'orange')),
- 3 => array('score' => 110, array('node_id'=>3, 'name'=>'something')),
- );
- $table2_result = array(
- 0 => array('score' => 90, 'value' => 'banana'),
- 1 => array('score' => 59, 'value' => 'grapes'),
- );
- $combined = array_merge($table1_result,$table2_result);
- foreach($combined as $key => $row){
- $result_one[$key] = $row['score'];
- if(isset($row['value'])){
- $result_two[$key] = $row['value'];
- }else{
- $result_two[$key] = $row['0'];
- }
- }
- array_multisort($result_one, SORT_DESC, $result_two, SORT_ASC, $combined);
- var_dump($combined);
- //result you wanted
- array(
- 110 => array('node_id'=>1, 'name'=>'apple'),
- 110 => array('node_id'=>3, 'name'=>'something'),
- 90 => 'banana',
- 89 => array('node_id'=>2, 'name'=>'orange'
- 59 => 'grapes'
- )
- // result this provides
- array(5) {
- [0] =>
- array(2) {
- 'score' =>
- int(110)
- [0] =>
- array(2) {
- 'node_id' =>
- int(1)
- 'name' =>
- string(5) "apple"
- }
- }
- [1] =>
- array(2) {
- 'score' =>
- int(110)
- [0] =>
- array(2) {
- 'node_id' =>
- int(3)
- 'name' =>
- string(9) "something"
- }
- }
- [2] =>
- array(2) {
- 'score' =>
- int(90)
- 'value' =>
- string(6) "banana"
- }
- [3] =>
- array(2) {
- 'score' =>
- int(89)
- [0] =>
- array(2) {
- 'node_id' =>
- int(2)
- 'name' =>
- string(6) "orange"
- }
- }
- [4] =>
- array(2) {
- 'score' =>
- int(59)
- 'value' =>
- string(6) "grapes"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement