Похожие чаты

Good, but can you modify your solution so that the

following does not happen?

(1000 iterations of both solutions).

Input:

$paragraph = "o'reilly and peter's dogs and cats";
$junk = ["'s",'/',',','.',';','-'];

Output of my solution:

Array
(
[0] => o'reilly
[1] => and
[2] => peter
[4] => dogs
[6] => cats
)
0.02592 secs

Output of your solution:

Array
(
[0] => o
[1] => reilly
[2] => and
[3] => peter
[4] => s
[5] => dogs
[6] => and
[7] => cats
)
10.00271 secs

In serveral cases your solutions is faster and not in the previous one. However the documentation says:

If you don't need the power of regular expressions, you can choose faster (albeit simpler) alternatives like explode() or str_split().

You must also be careful with: https://stackoverflow.com/questions/15137660/php-preg-split-utf8-characters

Finally, how to eliminate duplicate words with preg_split? I do this for my solution...

$duplicated = [];
$words = array_filter(
explode(' ',
str_replace($junk, ' ',$paragraph)),
function ($item) use (&$duplicated) {
if (trim($item) !== ""
&& !isset($duplicated[$item])) {
$duplicated[$item] = true;
return true;
}
return false;
});

Trim is better for clean chars like \n and performance is not greatly affected. But you can also add \n to $junk.

@being_void_xd

2 ответов

11 просмотров

Why do you ping, when you can just pong

Simply you could give those chars instead of \PL to preg_split. Also that 10 seconds is bulls***. Try it here https://3v4l.org/2u5cd Using preg_split, in this case, is much more faster.

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта