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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:34:07+00:00 2026-05-20T03:34:07+00:00

I have a array which contains values like this See below for script sample

  • 0

I have a array which contains values like this

See below for script sample

Suppose this is in a variable $Output_Data

I want to apply certain function on this $Output_Data listed below

  1. Remove Duplicate VALUE also associating KEY (but must keep one)
    i know this can be achieved by function array_unique but how to delete the array key
  2. If img exist than put it in a variable adding img tag example

    if exist img key in output data (or flv or mp4)
        $output_img[] = '<a href="$Output_Data[img]">Image "$i"</a>';
    

    Like this for every key i mean FLV, MP4, IMG

  3. Output to user screen Now again we created new Array separating the data

    $output_img[] 
    $output_flv[] 
    $output_mp4[]
    

So if the array contains data than output it to user screen…(here also check if they exist or empty)

I am not a pro in this thing i just want to add a feature to my website and i hate array a lot but it is the only thing that will help me.

You can also mention a Alternative Solution for this… Because it is just my thought not a Necessity.

Sorry for wrong code here is a sample script

function sortoutput($data_to_sort,$key_explode_char) {   
 $output_content = array();
    foreach (explode(PHP_EOL, $data_to_sort) as $cLine) { 
        list ($cKey, $cValue) = explode($key_explode_char, $cLine, 2); 
        $output_content[$cKey] = $cValue;
    }
    return $output_content;
    }
                    ob_start();
                            $flv = 'http://example.com/example.flv';
                            $flv2 = 'http://example.com/example2.flv';
                             $img = 'http://example.com/my.jpg';
                            $mp4 = 'http://example.com/okay.mp4';
                            print 'flv=`'.$flv.PHP_EOL;
                            print 'flv=`'.$flv2.PHP_EOL;
                            print 'img=`'.$img.PHP_EOL;
                            print 'mp4=`'.$mp4;
                            $Output_Download_Link = ob_get_contents();
                             ob_end_clean();


                            echo $Output_Download_Link;
                            $Sorted_Output_Links = sortoutput($Output_Download_Link, '=`');

                             echo '<pre>';
                            print_r($Sorted_Output_Links);
                            echo '</pre>';
  • 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-20T03:34:08+00:00Added an answer on May 20, 2026 at 3:34 am

    You have to switch keys and values. A key is always unique! You can’t have two or more entries with the same key name (except using a 2-dimensional array…).

    After this you can get the keys of an array with array_keys() and use array_unique()

    $array = array('url1' => 'flv', 'url2' => 'flv', 'url3' => 'png');
    $keys = array_keys($array); //all urls
    $keys = array_unique($keys); //remove url duplicates
    $output = array( //all extensions which should be stored in array
        'flv' => array(),
        'png' => array(),
        'mp4' => array(),
    );
    
    foreach($keys as $url) {
        $extension = $array[$url];
        if(isset($output[$extension])) {
            $id = count($output[$extension]) + 1;
            $output[$extension][] = "<a href=\"".$url."\">Image #".$id."</a>";
        }
    }
    
    foreach($output as $o) {
        //Output all arrays which aren't empty
        if(!empty($o)) {
            $o = implode('', $o);
            echo $o.'<hr />';
        }
    }
    

    A better way would be if you get the extension from the link directly using substr() and strrpos().

    Than you can check whether $output[$extension] exists and create first an empty array() on $output[$extension]. This way you are more flexible with the extensions…

    Edit: After you added a correct example…

    You have to change this line: $output_content[$cKey] = $cValue;

    //OLD: $output_content[$cKey] = $cValue;
    //NEW:
    if(!isset($output_content[$cKey])) {
        $output_content[$cKey] = array();
    }
    $output_content[$cKey][] = "<a href=\"".$cValue."\">".$cValue."</a>";
    

    And then you can check every entry of $output_content whether it is empty or not and output it. (have a look at the my first example above)

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

Sidebar

Related Questions

I have an array that contains a list of vertices which I copy to
I have an array which is a list of domains, I want to print
I have an array, which contains some duplicate entries. Firstly, is there any way
I have an array in PHP which holds a bunch of unix timestamps. As
I have an array of objects which populate a UITableView . When a user
I have a big lump of binary data in a char[] array which I
I have two questions: 1) How can I make an array which points to
I have an array of FileReference objects which have several listeners attached to each
I have a base class object array into which I have typecasted many different
I have a two-dimensional array (of Strings) which make up my data table (of

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.