I have wrote the following code:
$row_array = range( 1 , $puzzle_size , 1 );
$yes_array = array_rand( $row_array , $total_numbers_to_display );
The values of $puzzle_size and $total_numbers_to_display depends on the difficulty level:
$puzzle_size will be 8, 20 and 40 for easy, medium and hard levels. $total_numbers_to_display = 3
The value of $yes_array
is not giving me the output I need. What it gave me right now is:
Array
(
[0] => 1
[1] => 2
[2] => 3
)
What I am requiring is for there to be at least 1 number gap between each result.
Example 1:
Array
(
[0] => 1
[1] => 3
[2] => 5
)
Example 2:
Array
(
[0] => 1
[1] => 4
[2] => 7
)
Example 3:
Array
(
[0] => 2
[1] => 4
[2] => 7
)
I am unsure of how to do this.
2
Answers
The answer by
@PracticalOpportunist
got me on the right track. This is the function I wrote:Please edit your code as shown below :
Output is as expected in the question.