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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:32:59+00:00 2026-05-29T05:32:59+00:00

<?php $c = count($rank); // 5 for ($i = 0; $i < $c; $i++)

  • 0
<?php 
    $c = count($rank); // 5

    for ($i = 0; $i < $c; $i++) {
        $labels [] = array("value" =>$i, "text" => $i);
    }

?>

output: `[{"value":1,"text":1},{"value":2,"text":2},{"value":3,"text":3},{"value":4,"text":4},{"value":5,"text":5}]`

But what I need is:

[{"value":5,"text":1},{"value":4,"text":2},{"value":3,"text":3},{"value":2,"text":4},{"value":1,"text":5}]

Any idea about that?

  • 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-29T05:33:00+00:00Added an answer on May 29, 2026 at 5:33 am

    I’ll describe my line of thinking.

    What is the pattern in the sequence 5, 4, 3, 2, 1? Quite clearly, I decrease by one each time. I already know that $i increases by one each time, because that is how we wrote our for loop. My goal and what is available with $i is fairly close, so is there any way I can use $i?

    Indeed there is. Instead of saying the sequence 5, 4, 3, 2, 1 decreases by one each time, I can say that the sequence increases in its distance from 5 by one each time. That is, the sequence is equivalent to 5 - 0, 5 - 1, 5 - 2, 5 - 3, 5 - 4. Notice that this lines up perfectly with $i. Therefore, our solution can be the following:

    <?php 
    $c = count($rank); // 5
    
    for ($i = 0; $i < $c; $i++) {
          $labels [] = array("value" =>($c - $i), "text" => $i);
    }
    

    This takes a bit of intuition to see, and if you are in a similar situation and cannot figure out the pattern, you can always introduce a new variable.

    <?php 
    $c = count($rank); // 5
    
    
    for ($decreasing = $c, $i = 0; $i < $c; $i++, --$decreasing) {
          $labels [] = array("value" =>$decreasing, "text" => $i);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP array that I need to sort. I have included the
I know the function count() of php, but what's the function for counting how
How can we count space between text in PHP? example: hi how are you?
I am trying to write a PHP script that can upload multiple files. for($i=0;$i<count($_FILES['uploadimg']['name']);$i++){
I'm trying to search through this Json array using PHP: {count:2,items:{milestone:[{id:3107,username:TomSmith1,userid:1620602,date:2012-01-12 16:49:26,projectid:804,projectname:TEST PROJECT,reason:Partial payment
I'm trying to use a PHP Class in conjunction with javascript, but I need
How to remove duplicate values from an array in PHP and count the occurrence
Can any one help how to get facebook recommended count in php. I search
I have the following button: <input type=button count='<?php echo count($_SESSION['children']);?>' name=children class=add_child value=Add Another
I need to count words in a string using PHP or Javascript (preferably PHP).

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.