当前位置:网站首页>If the array values match each other, shuffle again - PHP

If the array values match each other, shuffle again - PHP

2022-07-04 07:53:00 45MA

I have a form , Users can go to 7 Enter numbers in different fields , And then use

shuffle($_POST);

Mixed numbers , Then compare them with the numbers originally entered , So the output is as follows :

1 12 43 64 25 76 37 5

This is the code I'm using .

<?php error_reporting(0);if ($_SERVER['REQUEST_METHOD']== "POST") {$array = implode("",$_POST);shuffle($_POST);}?><div class="box"><?php echo $array[0]; ?> <?php echo $_POST[0]; ?></div><br><div class="box"><?php echo $array[1]; ?> <?php echo $_POST[1]; ?></div><br><div class="box"><?php echo $array[2]; ?> <?php echo $_POST[2]; ?></div><br><div class="box"><?php echo $array[3]; ?> <?php echo $_POST[3]; ?></div><br><div class="box"><?php echo $array[4]; ?> <?php echo $_POST[4]; ?></div><br><div class="box"><?php echo $array[5]; ?> <?php echo $_POST[5]; ?></div><br><div class="box"><?php echo $array[6]; ?> <?php echo $_POST[6]; ?></div><br>

How to check the value of two arrays , To make sure they don't match . If they do match , Then I want to use it again shuffle(), Until there is no match . I might use if else Statement to run the code again , Until the numbers don't match , But I'm not sure how to deal with .

Reference plan

stay while Check in the loop array_intersect_assoc($array,$_POST);, Until an empty array is returned , Random broadcast !

Use array_intersect_assoc()

$array = $_POST;do {    shuffle($_POST);} while ((count(array_intersect_assoc($array, $_POST))) !=0);

php Singleton Will class instances be preserved in multiple sessions ? - php

Let's take a simple example , If I want to calculate the number of hits of a script that does not use disk storage , Can I use static class members to do this ? user 1:<?php $test = Example::singleton(); $test->visits++; ?> user 2:<?php $test = Example::singleton(); $test->visits+…

PHP- Check box group - php

I have a check box group of forms that need to be published .<input type="checkbox" value="true" checked name="chk0[]"> <input type="checkbox" value="false" name=…

When using jquery Of id When doing sth ,id Can it come from any kind of mark ? - php

I am a JQuery novice , I'm trying to use PHP,HTML and JQuery Write code . I want to use with ID Label replacement of HTML All in <?php echo $var; ?>. for example , I want to use <div id="name"></div> Things like that , And then use $("#name") Display it in this div Field . My question …

PHP It's strange sprintf Behavior - php

I try to do sprintf("<%s>", "Sat");, But nothing happened . When you delete the less than symbol , It will start working again . Anyone has experienced this behavior and whether it will happen ? Because I think this is a mistake . You can even use it here printf ..... Get the same results .http://writecodeonline.com/php/ ginseng …

jQuery It doesn't work - php

I'm using ajax Of jquery. Sometimes , Give a mistake $ Undefined . This is my code :<script language="javascript" type="text/javascript"> var base_path="<? echo $this->baseUrl().'/…

原网站

版权声明
本文为[45MA]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141517534342.html