vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Need Help with An Array (https://vborg.vbsupport.ru/showthread.php?t=177288)

noonespecial 04-27-2008 05:42 AM

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?

Dismounted 04-27-2008 07:14 AM

PHP Code:

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


noonespecial 04-27-2008 07:31 AM

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.

Dismounted 04-27-2008 07:48 AM

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); 


noonespecial 04-27-2008 10:07 AM

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') . '";');    
    }    



Dismounted 04-27-2008 10:25 AM

Can you give me the value of "$entry['tags']"?

noonespecial 04-27-2008 10:34 AM

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

Thanks again.

Dismounted 04-27-2008 10:56 AM

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') . '";');



noonespecial 04-27-2008 06:20 PM

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.


All times are GMT. The time now is 10:41 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01190 seconds
  • Memory Usage 1,746KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete