Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,941 questions

51,879 answers

573 users

How to reindex array in PHP

1 Answer

0 votes
$s = "PHP general-purpose PHP scripting PHP scripting language scripting PHP PHP"; 

$arr = preg_split("/[\s,-.]+/", $s);
print_r($arr);

$arr = array_unique($arr);
print_r($arr);

// reindex array
$arr = array_values($arr);
print_r($arr);





/*
run:

Array
(
    [0] => PHP
    [1] => general
    [2] => purpose
    [3] => PHP
    [4] => scripting
    [5] => PHP
    [6] => scripting
    [7] => language
    [8] => scripting
    [9] => PHP
    [10] => PHP
)
Array
(
    [0] => PHP
    [1] => general
    [2] => purpose
    [4] => scripting
    [7] => language
)
Array
(
    [0] => PHP
    [1] => general
    [2] => purpose
    [3] => scripting
    [4] => language
)

*/

 



answered Jun 26, 2021 by avibootz

Related questions

...