try something like this.
$set = array( 7, 8 );
echo '<pre>';
foreach( $set as $number ){
//assuming number is your INT
$array = range( 1, $number );
while( count( $array ) ){
echo "\n";
var_export( $array );
//remove first element
array_shift( $array );
//remove last element
array_pop($array);
}
}
Outputs:
For 7
array (
0 => 1,
1 => 2,
2 => 3,
3 => 4,
4 => 5,
5 => 6,
6 => 7,
)
array (
0 => 2,
1 => 3,
2 => 4,
3 => 5,
4 => 6,
)
array (
0 => 3,
1 => 4,
2 => 5,
)
array (
0 => 4,
)
For 8
array (
0 => 1,
1 => 2,
2 => 3,
3 => 4,
4 => 5,
5 => 6,
6 => 7,
7 => 8,
)
array (
0 => 2,
1 => 3,
2 => 4,
3 => 5,
4 => 6,
5 => 7,
)
array (
0 => 3,
1 => 4,
2 => 5,
3 => 6,
)
array (
0 => 4,
1 => 5,
)
I’ll leave it to you to build a multi-dimensional array out of that.
If you just want the output, than use echo implode(' ', $array );
in place of var_export()
. Such as this:
$set = array( 7, 8 );
echo '<div style="text-align:center">';
foreach( $set as $number ){
//assuming number is your INT
$array = range( 1, $number );
while( count( $array ) ){
echo implode(' ', $array );
//remove first element
array_shift($array);
//remove last element
array_pop($array);
echo '<br>';
}
echo '<br>';
}
echo '</div>';
Outputs:
1 2 3 4 5 6 7
2 3 4 5 6
3 4 5
4
1 2 3 4 5 6 7 8
2 3 4 5 6 7
3 4 5 6
4 5
6
solved How to make a graphic using numbers with PHP [closed]