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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:05:48+00:00 2026-06-06T02:05:48+00:00

I’m attempting to use the values from one JSON link to populate values in

  • 0

I’m attempting to use the values from one JSON link to populate values in other JSON links resulting in a unique list of values from the combined JSON. I’ve gotten as far as creating the complete list of values, but I’m having a difficult time finding the syntax in the final loop to display only the unique values. Any help would be appreciated.

$collection_string = file_get_contents("http://some_json_url.com/json");
$collection_list = json_decode($collection_string, true);

foreach ($collection_list as $col_lists => $col_list) {
     $object_string = file_get_contents('http://another_json_url.com/'.$col_list['key'].'/json');
     $object_list = json_decode($object_string, true);
     $object_array = array();

     foreach ($object_list as $objects => $object) {
          $object_array [] = array_unique($object); //Returns "Warning: array_unique() expects parameter 1 to be array, string given in..."
          echo '<li><a href="some_search_url/'.$object_array.'/search/">'.$object_array.'</a></li>'; //Returns "Array"
          echo '<li><a href="some_search_url/'.$object.'/search/">'.$object.'</a></li>'; //Returns complete list
     }

}

Working code:

$collection_string = file_get_contents("http://some_json_url.com/json");
$collection_list = json_decode($collection_string, true);

$object_array = array();

foreach ($collection_list as $col_lists => $col_list) {
     $object_string = file_get_contents('http://another_json_url.com/'.$col_list['key'].'/json');
     $object_list = json_decode($object_string, true);

     foreach ($object_list as $key => $value) {
          array_push($object_array, $value);
     }
}

$object_unique = array_unique($object_array);
natcasesort($object_unique);

foreach ($object_unique as $key => $value) {
     echo '<li><a href="some_search_url/'.$value.'/search/">'.$value.'</a></li>';
}
  • 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-06T02:05:51+00:00Added an answer on June 6, 2026 at 2:05 am

    Simply change this

    $object_array [] = array_unique($object);
    

    to that

    $object_array [] = $object; // edited !
    array_unique($object_array);
    

    Maybe you can also do this with one line of code, but I dont know how to write it. But the way the way I wrote it it’s a little bit unoptimized, it would be better to simply do the array_unique() only one time, right after the final loop.

    Btw your problem is/was that you tried to make $object unique, which is not an array. it’s a string/object.

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

Sidebar

Related Questions

Attempting to use the data series from this example no longer passes the JSONLint
When attempting to use HttpWebRequest to retrieve a page from my dev server, I
In attempting to use std::select1st from <functional> in a VS2008 project I found that
I am trying to copy some property values from one object to another (both
I have been attempting to use an android.preference.DialogPreference inflated from XML, but the documentation
I'm trying to change a series of links by inserting values from a dropdown
I am attempting to read hex values from a text file. There can be
I'm attempting to take values from a XML file and put them into a
I'm attempting to use the DecimalMin validator from NHibernates Validator library. Unfortunately, due to
I am attempting to use faceting to generate multiple maps filled with different values.

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.