PHP Stitching String ... Which is better ...

Source: Internet
Author: User
Cough... Some of the code that I wrote recently is a Review ...
But ... I don't know what kind of a ...

The ps:php version is 5.4 so don't tangle [] what's up ... This is the array.

1$rule = [' pid=etfscreener&formsubmit=1&etfpage=1&cn=cnus&cf=&go=&ta=&er=er1& Ry=&r1=&r3=&r5=&tac=1&erc=1&ryc=1&r5c=1 ', ' pid=etfscreener&formsubmit=1& Etfpage=1&cn=cnus&cf=&go=&ta=&er=er2&ry=&r1=&r3=&r5=&tac=1&erc=1 &ryc=1&r5c=1 ', ' pid=etfscreener&formsubmit=1&etfpage=1&cn=cnus&cf=&go=&ta=& Er=er3&ry=&r1=&r3=&r5=&tac=1&erc=1&ryc=1&r5c=1 ', ' pid=etfscreener& formsubmit=1&etfpage=1&cn=cnus&cf=&go=&ta=&er=er4&ry=&r1=&r3=&r5=& Tac=1&erc=1&ryc=1&r5c=1 ', ' pid=etfscreener&formsubmit=1&etfpage=1&cn=cnus&cf=& Go=&ta=&er=er5&ry=&r1=&r3=&r5=&tac=1&erc=1&ryc=1&r5c=1 ',];//2$rule = Array_map (function ($s) {return ' pid=etfscreener&formsubmit=1&etfpage=1&cn=cnus&cf=&go=& ta=&er=er{$s}&Ry=&r1=&r3=&r5=&tac=1&erc=1&ryc=1&r5c=1 ";}, Range (1, 5));//3$rule = [];for ($i = 1; $i < 6; $i + +) {$rule [] = "pid=etfscreener&formsubmit=1&etfpage=1&cn=cnus&cf=&go=&ta=&er=er{$i }&ry=&r1=&r3=&r5=&tac=1&erc=1&ryc=1&r5c=1 ";}

Reply content:

Cough... Some of the code that I wrote recently is a Review ...
But ... I don't know what kind of a ...

The ps:php version is 5.4 so don't tangle [] what's up ... This is the array.

1$rule = [' pid=etfscreener&formsubmit=1&etfpage=1&cn=cnus&cf=&go=&ta=&er=er1& Ry=&r1=&r3=&r5=&tac=1&erc=1&ryc=1&r5c=1 ', ' pid=etfscreener&formsubmit=1& Etfpage=1&cn=cnus&cf=&go=&ta=&er=er2&ry=&r1=&r3=&r5=&tac=1&erc=1 &ryc=1&r5c=1 ', ' pid=etfscreener&formsubmit=1&etfpage=1&cn=cnus&cf=&go=&ta=& Er=er3&ry=&r1=&r3=&r5=&tac=1&erc=1&ryc=1&r5c=1 ', ' pid=etfscreener& formsubmit=1&etfpage=1&cn=cnus&cf=&go=&ta=&er=er4&ry=&r1=&r3=&r5=& Tac=1&erc=1&ryc=1&r5c=1 ', ' pid=etfscreener&formsubmit=1&etfpage=1&cn=cnus&cf=& Go=&ta=&er=er5&ry=&r1=&r3=&r5=&tac=1&erc=1&ryc=1&r5c=1 ',];//2$rule = Array_map (function ($s) {return ' pid=etfscreener&formsubmit=1&etfpage=1&cn=cnus&cf=&go=& ta=&er=er{$s}&Ry=&r1=&r3=&r5=&tac=1&erc=1&ryc=1&r5c=1 ";}, Range (1, 5));//3$rule = [];for ($i = 1; $i < 6; $i + +) {$rule [] = "pid=etfscreener&formsubmit=1&etfpage=1&cn=cnus&cf=&go=&ta=&er=er{$i }&ry=&r1=&r3=&r5=&tac=1&erc=1&ryc=1&r5c=1 ";}

You're a dead bunny, and you got a code review.

These three kinds of writing ... If it is the finished code ... The first kind is absolutely undesirable ...

You know you are copy-paste and then only modified a number ... But the review people don't know ...

Even if he knew ... He's not sure if you've changed your hand.

In the inability to determine if you have this five-line code is not the same number of the same other cases ...

He needs to look carefully or use tools to confirm this ... This is actually adding unnecessary trouble to the reviewer ...

If it is code-generator or pre-processor generated code ... Undoubtedly the first is the most efficient ...

But if this code is handwritten ... Even if yy4p it's just a stupid act ...

Besides, the rest ... Under such a simple demand ... The second kind of writing is biased towards dazzle ... The third kind of comparison ...

I measured it a little bit ... The second way is 140% slower than the third.

Other words... The second type of execution efficiency is the third way of writing 240% ...

The numbers look awful ... But it's actually a millisecond-level gap ...

Let's not say what these milliseconds can do in the case of heavy loads and high concurrency ...

I just said a few milliseconds of wasting ... Speaking from any angle ... Have no meaning at all ... Did you hear the server cry?

There's one thing I have to say ... It's not that you write a third appearance, which means you don't have the power. Your code is not good to see ...

No front ... The big Qiao does not work ...

Juchongruoqing is a master should have the appearance of ... Like you are deliberately making trouble for the sake of dazzling skills ... It is really not to be taken.

Of course... It's just a time to put the code on the line and run ... Community communication Words in fact the second and the third difference is really not big ...

Incidentally ...

 

This type of Python is faster than you can use Array_map ...

Scenario 3

1. More code, to see the difference part is too difficult
2.2 and 3 average people will write 3. 2 Another downside is that the range first creates an array, or ARRAY_MAP is better.
3. Select 3 My personal reason is because the intuitive

If it is a repeating string, it is obviously str_repeat () better.
It is better to be the first if you do not repeat it, because it has been determined during compilation.
The second is the slowest functional programming. This one is weak in PHP. Python's notation does not necessarily apply (of course I did the test)
The third kind belongs to the

3 is a good extensibility. It's convenient to add new variables or increase the number of cycles in the future.
If you run into a running efficiency problem, you can simply render it in the first way (write a file or echo something):

for ($i = 1; $i < 6; $i + +) {     file_put_content ("pid=etfscreener&formsubmit=1&etfpage=1&cn=cnus& cf=&go=&ta=&er=er{$i}&ry=&r1=&r3=&r5=&tac=1&erc=1&ryc=1&r5c=1 ");}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.