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

  • SEARCH
  • Home
  • 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 9089673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:12:14+00:00 2026-06-16T22:12:14+00:00

I’m new to PHP. A friend was helping me learn this, but he’s not

  • 0

I’m new to PHP. A friend was helping me learn this, but he’s not available for a while. I know some things may simply not make sense (i’m learning, and I know this isn’t exactly a beginners function).

GOAL:
1. Find highest and lowest value within the array ($lemons).
2. Switch the placement of said values. (IE: 6, 2, 7, 8, 0, 9 –> 6, 2, 7, 8, 9, 0).

Thanks!

 <?php
 function switcheroo($lemons) {
    $min_lemons = min($lemons);
    $max_lemons = max($lemons);
    foreach ($lemons as $key => $value) {
        if ($max_lemons > 0) {
            $max_decoy = $min_lemons;
        }
        if ($min_lemons < 0) {
            $min_decoy = $max_lemons;
        }
    }
    return $lemons;
 }
 $lemons = array(6, 2, 7, 8, 0, 9);
 print_r(switcheroo($lemons));
 ?>
  • 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-06-16T22:12:15+00:00Added an answer on June 16, 2026 at 10:12 pm

    This is probably not the most elegant solution, but it works as intended:

    $arr = array(6, 2, 7, 8, 0, 9);
    
    echo 'Array before: <br /><pre>', print_r($arr, true);
    
    function switcheroo($array) {
        $new_array = $array;
    
        $min_lemons = min($new_array);
        $max_lemons = max($new_array);
    
        $min_lemons_key = array_search($min_lemons, $new_array);
        $max_lemons_key = array_search($max_lemons, $new_array);
    
        $new_array[$min_lemons_key] = $max_lemons;
        $new_array[$max_lemons_key] = $min_lemons;
    
        return $new_array;
    }
    
    echo 'Array after: <br />', print_r(switcheroo($arr), true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.