Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-27-2008, 05:42 AM
noonespecial noonespecial is offline
 
Join Date: Nov 2002
Posts: 250
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Need Help with An Array

I have an array that looks kind of like this:

$array = array("rss", "rss, happy, total", "total, happy, yesterday");

Now what I'd like to do is remove all of the duplicates so I have one array that looks like this - just one element in each value.

$array = array("rss", "happy", "total", "yesterday");

How could I do this?
Reply With Quote
  #2  
Old 04-27-2008, 07:14 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$array = array("rss""rss""happy""total""total""happy""yesterday");
$array array_unique($array); 
Reply With Quote
  #3  
Old 04-27-2008, 07:31 AM
noonespecial noonespecial is offline
 
Join Date: Nov 2002
Posts: 250
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, but how do I get that first array?

It's already set as:

$array = array("rss", "rss, happy, total", "total, happy, yesterday");

That's in the database already, I can't just change it -- well, my question is, how do I change it to a way I can use array_unique.
Reply With Quote
  #4  
Old 04-27-2008, 07:48 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$array = array("rss""rss, happy, total""total, happy, yesterday");
$tmparray = array();

foreach (
$array AS $value)
{
    
$exploded explode(','$value);

    foreach (
$exploded AS $explode)
    {
        
$tmparray[] = $explode;
    }
}

$array array_unique($tmparray); 
Reply With Quote
  #5  
Old 04-27-2008, 10:07 AM
noonespecial noonespecial is offline
 
Join Date: Nov 2002
Posts: 250
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Tried it and still had duplicates. Am I missing something?

:-/ Thanks for your help by the way!

PHP Code:
$entries $db->query_read("SELECT DISTINCT tags FROM " TABLE_PREFIX "journal_entries WHERE journal_id =" $j." AND tags IS NOT NULL AND tags <> '' ORDER BY tags ASC LIMIT 200");

while (
$entry $vbulletin->db->fetch_array($entries))
    {
    
    
$array strtolower($entry['tags']);
    
$array explode(','trim($entry['tags']));

    
$tmparray = array();

    foreach (
$array AS $value)
    {
    
$exploded explode(','$value);

    foreach (
$exploded AS $explode)
    {
        
$tmparray[] = $explode;
    }
    }

    
$kwords array_unique($tmparray);
        
    foreach (
$kwords AS $keyword)
    {
    
$keyword trim($keyword);
    eval(
'$blogtags .="' fetch_template('blogtag') . '";');    
    }    

Reply With Quote
  #6  
Old 04-27-2008, 10:25 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can you give me the value of "$entry['tags']"?
Reply With Quote
  #7  
Old 04-27-2008, 10:34 AM
noonespecial noonespecial is offline
 
Join Date: Nov 2002
Posts: 250
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Maybe I'm making a mistake -- so here's the output (value of $entry['tags']) from the query I am running.

Thanks again.
Attached Images
File Type: gif example copy.gif (230.4 KB, 0 views)
Reply With Quote
  #8  
Old 04-27-2008, 10:56 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$entries $vbulletin->db->query_read("
    SELECT DISTINCT tags
    FROM " 
TABLE_PREFIX "journal_entries
    WHERE journal_id = 
$j
        AND tags IS NOT NULL
        AND tags <> ''
    ORDER BY tags ASC
    LIMIT 200
"
);

$tags = array();

while (
$entry $vbulletin->db->fetch_array($entries))
{
    
$tag_entry explode(', 'strtolower(trim($entry['tags'])));
    
$tags array_merge($tags$tag_entry);
}

$tags array_map('trim'$tag_entry);
$tags array_unique($tags);

foreach (
$tags AS $keyword)
{
    eval(
'$blogtags .="' fetch_template('blogtag') . '";');

Reply With Quote
  #9  
Old 04-27-2008, 06:20 PM
noonespecial noonespecial is offline
 
Join Date: Nov 2002
Posts: 250
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm, this only returned three results:

recommendation, avatar, ap related


--------------- Added [DATE]1209324149[/DATE] at [TIME]1209324149[/TIME] ---------------

However, removing "$tags = array_map('trim', $tag_entry);" seems to have done it.

--------------- Added [DATE]1209325454[/DATE] at [TIME]1209325454[/TIME] ---------------

Of course - sort() doesn't work on this -- but it seems to work for what I need!

Thank you so much!!! I appreciate it.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:25 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04038 seconds
  • Memory Usage 2,279KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (1)postbit_attachment
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete