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 7218289
In Process

The Archive Base Latest Questions

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

I asking about this case(replace item by position : highest with lowest etc.. ):

  • 0

I asking about this case(replace item by position : highest with lowest etc.. ):

my inputs:

// case1:
array('orange','blue','red');

// case2:
array('orange','blue','red','white');

should get outputs:

// case1:
array('red','blue','orange');

// case2:
array('white','red','blue','orange');

its can be done by – but i am looking for more shorter way:

function myReplaceArr(array $arr){     
 $len=count($arr);  
 $loopLen=(int)($len/2);    
 for($i=0;$i<$loopLen;$i++){
   $temp=$arr[$i];
   $arr[$i]=$arr[$len-$i-1];
   $arr[$len-$i-1]=$temp;
 }
 return $arr;
}
var_export(myReplaceArr(array('orange','blue','red')));
var_export(myReplaceArr(array('orange','blue','red','white')));
  • 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-28T21:27:46+00:00Added an answer on May 28, 2026 at 9:27 pm

    Thats called array_reverse();

    $array_1 = array('orange','blue','red');
    $array_2 = array('orange','blue','red','white');
    
    $array_1_new = array_reverse($array_1);
    $array_2_new = array_reverse($array_2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see a number of other people asking about this error message in other
I'm a bit ashamed about asking this, but how do i output the value
Similar to this question asking about relatively light-weight data entry / editor application development,
Please do not flag this as a duplicate, I'm not asking about what is
I'm wondering about the feasability of this below. Of course, I'm not asking for
In response to this question asking about hex to (raw) binary conversion, a comment
Well I want your opinions about this case: I need a database that will
I am asking about the static binding of the function in C++. What's the
i just was asking about the existence of a headfirst book(iPhone&iPad development) which covers
I'm asking about using a Twitter Bootstrap modal window with a Rails form helper

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.