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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:22:46+00:00 2026-05-24T03:22:46+00:00

PHP. I have three arrays, filled with 50 items each: $articles, $quotes, $links. Each

  • 0

PHP. I have three arrays, filled with 50 items each: $articles, $quotes, $links. Each item in each array has a line of content and a date.

The objective is to create one array, sorted by date (newest to oldest), that weights based on the importance of the array type. For example, it should always show more articles than quotes, and more quotes than links. For example:

Article, article, article, quote, article, link, article, article, quote, article, article, quote, article, link.

Is there any simple way to do this? Thanks!

  • 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-24T03:22:46+00:00Added an answer on May 24, 2026 at 3:22 am

    You could take advantage of the mod operator.

    $result = array();
    $i = 0;
    $count = 0;
    while( true ) {
      $i++;
    
      $result[] = array_pop( $articles );
      if (++$count >= 50) break; // 50 items is enough
    
      if ( $i % 3 == 0 ) { // one quote every 3 articles
           $result[] = array_pop( $quotes );
           if (++$count >= 50) break;
      }
    
      if ( $i % 5 == 0 ) // one link every 5 articles
           $result[] = array_pop( $links );
           if (++$count >= 50) break;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three PHP arrays that I've encoded with json... extra PHP code has
I have three files: one called sql.php witch has a class db that I
A PHP array can have arrays for its elements. And those arrays can have
I have an array filled with paths looking like this: library/main/single/list.php library/article/grid/thumbs.php library/footer/tiny.php These
Possible Duplicate: Transposing multidimensional arrays in PHP I have three arrays: $a = (a1,
I have PHP array of arrays as below and I want to extract the
i have three arrays in php script $arr1=(a,b,c) //(1,2,3) $arr2=(d,e,f) //(4,5,6) $arr3=(g,h,i) //(7,8,9) note
I have a nested array grouping three other arrays: $online, $busy and $offline, in
I have three update statements to be executed in PHP, i am getting the
I have three files in a folder 'test' one.php two.php print.html And i have

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.