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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:24:50+00:00 2026-05-16T14:24:50+00:00

i’m able to split a string into an array $array = preg_split(/[\s]*[,][\s]*/, $category); RESULT

  • 0

i’m able to split a string into an array

$array  = preg_split("/[\s]*[,][\s]*/", $category); 

RESULT 

Array ( [0] => jquery[1] => bla[2] => bla);

but now i have a database with a row holding all by categories (“cat1, 2, 3, ..”) – multiple records have similar categories- so in order to create a quick “category” menu i’m using this code this code:

           while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
        $category[] = $row[category];
}   
    $array = array_unique($category);

as you can imagine the result is like this:

Array ( [0] => bla1,bla2, bla3[1] => bla6, bla4[2] => bla11 ….);

is there a way to slip this array so that (one more time) i get a slip array

i have used the above “array_unique” method but is not working – though all google searches lead me to the same result (being the above one)

hope you could help

thanks

  • 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-16T14:24:51+00:00Added an answer on May 16, 2026 at 2:24 pm

    First of: Splitting a string is easier with the explode() function.

    Guessing what you want to do i wrote up a little code sample:

    <?php
    $dbRows = array("x,y,z", "a,b,c", "y,b,c");
    
    $allCats = array();
    foreach($dbRows as $row) {
        $allCats = array_merge($allCats, explode(",", $row));
    }
    
    var_dump(array_unique($allCats));
    
    /*
    array(6) {
      [0]=> string(1) "x"
      [1]=> string(1) "y"
      [2]=> string(1) "z"
      [3]=> string(1) "a"
      [4]=> string(1) "b"
      [5]=> string(1) "c"
    }
    */
    

    so you take out all of the values, fill a big array with those and filter it out at the end.

    I hope this is what you are trying to do.


    On a sidenote: Just in general it is not considered “good practice” to store stuff in your database that you need to perform string operations on.
    You might want to only store one value per column to make your live easier.

    ( See this Stackoverflow question: What is Normalisation (or Normalization)? )

    Edit

    A shorter version of the above code with the same output:

    <?php
    $dbRows = array("x,y,z", "a,b,c", "y,b,c");
    $allCats = explode(",", implode(",", $dbRows));
    var_dump(array_unique($allCats));
    

    this creates one big string ( “x,y,z,a,b,c,y,b,c” ) and splits that one. Left the above example as i’d guess it is easier to read/clearer

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and

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.