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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:46:55+00:00 2026-05-26T14:46:55+00:00

I am trying to integrate this logic in my script but I can’t really

  • 0

enter image description here

I am trying to integrate this logic in my script but I can’t really get a good grab around this or find any search function that will perform this..

I am trying to make a code snippet that arranges an array in the order of what the value of $onca is. $onca is a randomly changing variable and its possible values consist of the elements in an array $oncMail. Everytime $onca changes to a new value I would like the array to sort it self out by taking the new variable’s location in the array and swapping it with the old value’s position so that the new value becomes the 1st in the array and the old one goes to the position of index in the array of old value. To make more sense I have attached a picture of the logic process..

  • 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-26T14:46:55+00:00Added an answer on May 26, 2026 at 2:46 pm

    Whenever the value of $onca changes, use array_search to find the corresponding element and swap it with the first one:

    $array = range(0, 10);
    $onca = 3;
    
    print_r($array); // starting array
    $key = array_search($onca, $array, true);
    reset($array); // so that key() below works as intended, no questions asked
    $firstKey = key($array);
    if ($key !== false && $key !== $firstKey) {
        $temp = $array[$firstKey];
        $array[$key] = $temp;
        $array[$firstKey] = $onca;
    }
    print_r($array); // final array
    

    See it in action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to integrate a NSURLConnection object with UIProgressView, so I can update the
I am trying to integrate the function into a map where you can enter
I'm trying to integrate facebook login on a site I'm working on, but so
I am trying to integrate Facebook to one of my projects. At this time
I am trying to integrate openID with the FOSUserBundle on the basis of this
I am trying to integrate an external script with wordpress.. I need t create
I am trying to integrate openid authentication in asp.net 4 following this article .
I am trying to integrate the following Blog app to my site,I get the
I am trying to integrate cpanel to my cms... I have this code to
I'm trying to get to grips with how Lua works, and how it can

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.