View difference between Paste ID: AUEBBhbd and qs4YcbeJ
SHOW: | | - or go back to the newest paste.
1
<?php
2
$array = ['+', '-', '/', '%'];
3
$totype = ['intval', 'floatval', 'strval', 'boolval',  /* 'arrayval'*/];
4
$from = $to = 10;
5
$min = 1;
6
$max = 100;
7
while ($i < $to) {
8
    $i++;
9
    $a = mt_rand($min, $max);
10
    $b = mt_rand($min, $max);
11
    $a = $totype[$i % count($totype)]($a);
12
    $b = $totype[$i % count($totype)]($b);
13
    foreach ($array as $index => $item) {
14
        $result = false;
15
        try {
16
            eval($str = '$result =' . '(' . $a . ')' . $item . '(' . $b . ')' . ';');
17
        } catch (Exception $e) {
18
            $Result[] = compact(['str', 'result', 'a', 'item', 'b', 'status' => $e->getMessage()]);
19
        }
20
        $Result[] = compact(['str', 'result', 'a', 'item', 'b', 'status' => true]);
21
    }
22
}
23
$tr[] = '<tr>';
24
$tr[] = '<th>#</th>';
25
$tr[] = '<th>a</th>';
26
$tr[] = '<th>тип (a)</th>';
27
$tr[] = '<th>операция</th>';
28
$tr[] = '<th>b</th>';
29
$tr[] = '<th>тип  (b)</th>';
30
$tr[] = '<th>=</th>';
31
$tr[] = '<th>тип (=)</th>';
32
$tr[] = '<th>str</th>';
33
$tr[] = '</tr>';
34
foreach ($Result as $index => $item) {
35
    $tr[] = '<tr>';
36
    $tr[] = '<td>' . $index . '</td>';
37
    $tr[] = '<td>' . $item['a'] . '</td>';
38
    $tr[] = '<td>' . (gettype($item['a'])) . '</td>';
39
    $tr[] = '<td>' . $item['item'] . '</td>';
40
    $tr[] = '<td>' . $item['b'] . '</td>';
41
    $tr[] = '<td>' . (gettype($item['b'])) . '</td>';
42
    $tr[] = '<td>' . $item['result'] . '</td>';
43
    $tr[] = '<td>' . (gettype($item['result'])) . '</td>';
44
    $tr[] = '<td class="str">' . $item['str'] . '</td>';
45
    $tr[] = '</tr>';
46
}
47
echo '<table align="center" class="table">' . implode(PHP_EOL, $tr) . '</table>
48
 <style>.table{border-collapse: collapse;  min-width: 960px} .table.th, table.td{border:1px solid  black; padding: 2px;} table  tr:nth-child(5n) td{background-color: #0b70db;}</style>';
49
50
51
52
echo '<table border=1>';
53
for ($i=0; $i<=255; $i += 50)
54
{
55
    echo '<tr>';
56
57
    for ($j=0; $j<=255; $j += 50)
58
    {
59
        for ($k=0; $k<=255; $k += 50)
60
        {
61
            echo '<td style="background-color:RGB('.$i.', '.$j.', '.$k.');"> rgb('.$i.', '.$j.', '.$k.')</td>';
62
        }
63
    }
64
65
    echo '</tr>';
66
}
67
echo'</table>';