how to split string into an array and sort them

sort array of strings c++
sort the strings based on the length of the string in an array
bubble sort
sort array of strings in c
java split string into array of strings
sort array by string length javascript
array.sort c#
how to divide a string into substrings in java

i am working on a module where i have stored string in a column separated by comma(,) and i have split the string into an array and added the array into drop down, but when i am doing this with multiple columns, its not sorting the array in dropdown

here is the code

   $pp=DB::table('gcp_projects')->where('niche','!=',' ')->where('niche','!=','')->where('niche','!=',null)->orderBy('niche')->pluck('niche');
$testing=explode(",",$pp);


$arr=array();
$tttt=array();
for($i=0;$i<=count($pp);$i++)
{
 $arr= explode(",",$pp);
 $temp = preg_replace("/[^a-zA-Z 0-9]+/", "", $arr);
$tttt=array_unique($temp);
sort($tttt);

}
<?php 

// Use preg_split() function 
$string = "123,456,78,000"; 
$str_arr = preg_split ("/\,/", $string); 
print_r($str_arr); 

// use of explode 
$string = "123,46,78,000"; 
$str_arr = explode (",", $string); 
print_r($str_arr); 
?> 

you can do it like this and use sort option like

$values = array ("zercggj.co.uk", "lkjhg.org.au", "qqxze.org.au",
                 "bfhgj.co.uk", "sdfgh.org.uk");

echo "<br>input:<br>";
foreach ($values as $host) echo "$host<br>";

// create a suitable structure
foreach ($values as $host)
{
    $split = explode('.', $host, 2);
    $printable[$split[1]][] = $split[0];
}

// sort by domains
asort ($printable);

// output
echo "<br>sorted:<br>";
foreach ($printable as $domain => $hosts)
{
    echo "domain: $domain<br>";

    // sort hosts within the current domain
    asort ($hosts);

    // display them
    foreach ($hosts as $host)
        echo "--- $host<br>";
}

Sort an array of strings according to string lengths, We are given an array of strings, we need to sort the array in increasing order of string A simple solution is to write our own sort function that compares string lengths to These functions also allow us to write our own custom comparator. substrings having palindromic permutations · Split the given string into Primes  I am trying to sort a string split by comma. But it is not behaving as expected First convert each element of array into integer and try to order – SPnL Aug 8

So Far i found this solution which is working for me

$pp=DB::table('gcp_projects')->whereNotNull('niche')->orderBy('niche')->pluck('niche')->toArray();


$aa=implode(',',$pp);

$myArray = explode(',', $aa);
$im=implode(' ',$myArray);
$ex=explode(' ',$im);
$tttt=array_unique($ex);
 sort($tttt);
 $str = preg_replace("/[^a-zA-Z 0-9]+/", "", $tttt);
  $result = array_filter($str); 

Print array of strings in sorted order without copying one string into , Approach: It has the following steps: Maintain another array indexed_arr which stores/maintains the index of each string. We can apply any  To convert the split string into an array in VBA we have a function called “SPLIT”. This is a VBA function that performs the task of splitting supplied string value to different parts based on the delimiter provided. For example, if the sentence is “Bangalore is the capital city of Karnataka” space is the delimiter between each word.

you have to mention orderby ASC OR DESC

orderBy('created_at', 'asc') Or orderBy('created_at', 'asc')

Array.Sort Method (System), Sorts the elements in a one-dimensional array. that reverses the default sort order for instances of a type and performs case-insensitive string comparison. NET Framework 4.5, it is possible that sorting operations that previously threw  Breaking the idea into smaller pieces, these are commands we need to define. Check connected devices and save the result into a string. Split connected devices string into an array to find device ids.

How to Split a String in Java: Learn with Example, Limit: A limit is a maximum number of values the array. If it is omitted or zero, it will return all the strings matching a regex. Split String Example. extension String { func splitBy(characters: [Character], swallow: Bool = false) -> [String] { var substring = "" var array = [String]() var index = 0 for character in self.characters { if let lastCharacter = substring.characters.last { // swallow same characters if lastCharacter == character { substring.append(character) } else { var shouldSplit = false // check if we need to split already for splitCharacter in characters { // slit if the last character is from split characters or the

Javascript sort string alphabetically without using sort method, Previous: Write a program in C# Sharp to sort a string array in ascending order. objects in the array to strings, sort them pseudo-alphabetically, and return them. The split() method of string class returns a list of words separated by space  The split() method is used to split a string into an array of substrings, and returns the new array. Tip: If an empty string ("") is used as the separator, the string is split between each character. Note: The split() method does not change the original string.

Need Help with Sorting a split string (Beginning Java forum at , (Probably easiest) Set up a Comparator that compares your strings by the numeric portion and then run Arrays.sort() on it. 2. Use delims = "[|;]" for  A Php Explode Array To String Album. The explode function a splits string based explode string. Enter full size Php Explode Array To String image

Comments
  • You're looping through the array $pp but in the loop you're still using $pp. You would need to use $pp[$i] for it to explode on the right item.
  • $tttt will always have the value of the last iteration of the for loop, I don't think this is what you want. What are you trying to achieve?
  • where('niche','!=',null) You don't check for NULL this way. Use whereNotNull(). Also, what's the point of this question? What are you sorting? Your input and expected output?
  • thanks for the feedback, i have stored multiple niche (3 niche per column) i have to get these niche seperated and sort it in a dropdown list, but its showing half sorted and half unsorted