Modify a piece of code, expert advice

Source: Internet
Author: User
Tags shuffle
$char = "111112222233333";p Reg_match_all ("| (. *)| U ", $char, $out, Preg_pattern_order), Echo $out [0][0];echo $out [0][1];echo $out [0][2];



The above code can get the value between the strings, but the effect I want is

I don't know how many nnnnn there are in the string, I want to get all the values between all the div and shuffle the order randomly.
such as the string "11111222223333344444";
The result I want to get is: 22222444443333311111


Trouble to know the master directly to the complete code, thank you


Reply to discussion (solution)

Added: There are Chinese characters between the Div

$char = "111112222233333"; $ary = Explode (", $char); shuffle ($ary); foreach ($ary as $v) {echo". $v;}

$char = "111112222233333";
$ary = Explode (' ', $char);
Shuffle ($ary);
foreach ($ary as $v)
{
if ($v! = "") {
Echo '. $v;
}
}
Upstairs the addition of a judgment value is not empty better point, the array will be more than one loop, followed by a more

Thank you upstairs two elder brother, this is a cycle
So how do you put this value back in a string?
For example $char1 = ' '

Code should be how to write, the younger brother does not understand PHP, again trouble, thank you

$char = "111112222233333";p Reg_match_all ("| (. *)| U ", $char, $out, Preg_pattern_order); Shuffle ($out [0]); $s = Join (", $out [0]); Echo $s;


By

Use the code on the 5 floor.

$char = "111112222233333";p Reg_match_all ("| (. *)| U ", $char, $out, Preg_pattern_order); Shuffle ($out [0]); $char = Join (", $out [0]); Echo $char;
  • Related Article

    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.