-2

I have an array of string like this :

array{"CTT29","CTT37","CTT41","CTT","CTT43"}

And I want to find the occurence in all strings, in this example it should give me "CTT"

Thanks a lot for your answers ! :)

Edit : sorry I've forgot the "s" ( I'm not good in english :/ )

1 Answers1

0

I didn't understand your needs but maybe this will help you.

<?php

$arr = array("CTT29","CTT37","CTT41","CTT","CTT43");

function occurrence(&$item){
    $keywords = preg_split("/[\d,]+/", $item);
    $item = $keywords[0];
}

echo "BEFORE\n";
var_dump($arr);

array_walk($arr, 'occurrence');

echo "AFTER\n";
var_dump($arr);

$ctt = array_unique($arr);

echo "CTT\n";
var_dump($ctt);

Result: https://eval.in/754295

Also see :

http://php.net/manual/tr/function.array-walk.php

http://php.net/manual/tr/function.array-unique.php

http://php.net/manual/tr/function.preg-split.php

B.Kocaman
  • 800
  • 4
  • 13