Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1074997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:12:45+00:00 2026-05-16T21:12:45+00:00

I m facing problem in sorting this 2-d array on the basis of key

  • 0

I m facing problem in sorting this 2-d array on the basis of key eg(33 in the sample code)
so the output will look like 7,7,28,33,35,38.Here is the sample code.

thanks in advance

<?php
$arr=array ( 0 => array ( 33 => 'SY2', ), 1 => array ( 38 => 'PR25', ), 2 => array ( 7 => 'SK22', ), 3 => array ( 7 => 'BT1', ), 4 => array ( 28 => 'WN8', ), 5 => array ( 35 => 'ST21', ));
print_r($arr);
$arrnew=array();
$str=0;
for($j=0;$j<count($arr);$j++){
 foreach($arr[$j] as $key=>$val){
  if($str == 0)
   $str=$arrnew[$key];
  if($str < $arrnew[$key])

  //$arrnew[$key]=$val;
  //echo $key."<BR>";
 }
}

print_r($arrnew);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:12:45+00:00Added an answer on May 16, 2026 at 9:12 pm
    $arr=array ( 0 => array ( 33 => 'SY2', ), 1 => array ( 38 => 'PR25', ), 2 => array ( 7 => 'SK22', ), 3 => array ( 7 => 'BT1', ), 4 => array ( 28 => 'WN8', ), 5 => array ( 35 => 'ST21', ));
    foreach($arr as $key => $val)
    {
     foreach ($val as $key2 => $val2)
     {
      $sort[$key] = $key2;
     }
    }
    array_multisort($sort, SORT_ASC, $arr);
    print_r($arr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

iam facing problem in passing array to view. this is my controller code.. function
I am facing problem in big decimal no. Following code snippet will explain my
Iam facing problem in understanding and converting a matlab code into opencv. I want
Im facing problem with poor performance of css prompting mechanism. Can I dissable this
I'm facing the same problem as explain in this post . In my case,
i am facing problem with the return type for this function and not really
I am facing problem with hibernate annotations.For the code shown below I have a
I am facing problem with sql query when I try to join this tree
I am facing a strange problem while sorting a list of strings with integer
Facing problem with every fetch i want to make using EF Query model.Place here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.