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

The Archive Base Latest Questions

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

I’ve been making a combined social media feed class which gets posts from Facebook

  • 0

I’ve been making a combined social media feed class which gets posts from Facebook and blogger and tweets from Twitter. It then combines them into one list for display on a site. The problem is that it’s rare to see either of the post types because twitter is a lot more active than the other two.

I managed to make it always display at least one of each type, however I did this by counting up the number of each type in the final array and then splicing them onto the end if there were none and am wondering if there is a more elegant solution to this?

My array contains a bunch of arrays which each have a ‘type’ value, this is the what I need to test for / have at least one of each.

before splice:

Array
(
    [0] => Array
        (
            [id] => 131403235838803968
            [from] => foo
            [sent] => 1320163947
            [type] => tweet
            [html] => bar
        )

    [1] => Array
        (
            [id] => 131403233250914304
            [from] => foo
            [sent] => 1320163946
            [type] => tweet
            [html] => bar
        )

    [2] => Array
        (
            [id] => 131403232835674113
            [from] => foo
            [sent] => 1320163946
            [type] => tweet
            [html] => bar
        )

    [3] => Array
        (
            [id] => 131403230910480384
            [from] => foo
            [sent] => 1320163946
            [type] => tweet
            [html] => bar
        )

    [4] => Array
        (
            [id] => 131403228834299904
            [from] => foo
            [sent] => 1320163945
            [type] => tweet
            [html] => bar
        )

    [5] => Array
        (
            [type] => facebook
            [from] => foo
            [html] => bar
            [sent] => 1320065996
        )

    [6] => Array
        (
            [type] => facebook
            [from] => foo
            [html] => bar
            [sent] => 1319808945
        )

    [7] => Array
        (
            [type] => facebook
            [from] => foo
            [html] => bar
            [sent] => 1319789640
        )

    [8] => Array
        (
            [type] => facebook
            [from] => foo
            [html] => bar
            [sent] => 1319707799
        )

    [9] => Array
        (
            [type] => facebook
            [from] => foo
            [html] => bar
            [sent] => 1319617295
        )

    [10] => Array
        (
            [type] => blogger
            [from] => foo
            [html] => bar
            [sent] => 1320157500
        )

    [11] => Array
        (
            [type] => blogger
            [from] => foo
            [html] => bar
            [sent] => 1320148260
        )

)

and after it will just have the 5 newest. However I want it to have the five newest but make sure that it has at least one with type ‘blogger’ and one with type ‘facebook’ in the final array.

Got it work using Johnny Craig’s idea and the following code:

$output = array();  
$output[] = $tweets[0];
$output[] = $items[0];
$output[] = $posts[0];
$feed = array_merge($tweets, $items, $posts);
$i = 0;
while ($limit > count($output)) {
    if (!in_array($feed[$i], $output)) {
        $output[] = $feed[$i];
    }
    $i++;
}

But not really sure I like it

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

    I ended up using the following based on @Johnny Craig’s idea.

    if ( !empty($tweets) ) $output[] = $tweets[0];
    if ( !empty($items) ) $output[] = $items[0];
    if ( !empty($posts) ) $output[] = $posts[0];
    $feed = array_merge($tweets, $items, $posts);
    $i = 0;
    while ( $limit > count($output) ) {
        if (!in_array($feed[$i], $output)) {
            $output[] = $feed[$i];
        }
        $i++;
    }
    

    Which is the same as above, except that I needed add in the if (!empty()) bits incase there were none of a certain type .

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the 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.