04c01-1.php
来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 61 行
PHP
61 行
<style type="text/css">table { border-collapse: collapse; }td, th { border: 1px solid #333333; width: 25px; text-align: center;}</style><?php// Create an array of values. The key is a printable version of it:$values = array("'0'" => '0', 0 => 0, "'1'" => '1', 1 => 1, "'-1'" => '-1', -1 => -1, "'2'" => '2', 2 => 2, '0.0' => 0.0, '0.1' => 0.1, '-0.1' => -0.1, '1.0' => 1.0, "'0.0'" => '0.0', "'0.1'" => '0.1', "'.1'" => '.1', "'-0.1'" => '-0.1', "'-.1'" => '-.1', "'1.0'" => '1.0', "'00'" => '00', "'01'" => '01', 'false' => false, 'true' => true, "''" => '', "'a'" => 'a', "'b'" => 'b', "'A'" => 'A', 'NULL' => NULL, 'array()' => array(), "array('a')" => array('a') );// Create an array of comparison functions, The Key is the printable version$cmp = array ( '==' => create_function('$a,$b', 'return $a == $b ? "<b>1</b>" : 0;'), '===' => create_function('$a,$b', 'return $a === $b ? "<b>1</b>" : 0;'), '!=' => create_function('$a,$b', 'return $a != $b ? "<b>1</b>" : 0;'), '!==' => create_function('$a,$b', 'return $a !== $b ? "<b>1</b>" : 0;'), '<' => create_function('$a,$b', 'return $a < $b ? "<b>1</b>" : 0;'), '>' => create_function('$a,$b', 'return $a > $b ? "<b>1</b>" : 0;'), '<=' => create_function('$a,$b', 'return $a <= $b ? "<b>1</b>" : 0;'), '>=' => create_function('$a,$b', 'return $a >= $b ? "<b>1</b>" : 0;'), 'strcmp()' => create_function('$a,$b', 'return @strcmp($a,$b);'), 'strcasecmp()' => create_function('$a,$b', 'return @strcasecmp($a,$b);'), );// Now, for every comparison function, create a reference table.foreach ($cmp as $name => $function) { create_reference_table($values, $name, $function);}// The function that creates the reference tables for usfunction create_reference_table($array, $name, $func) { // Start off the table echo '<br /><table>'; echo "<caption>PHP comparisons with operator: {$name}</caption>"; // Now create the first header row echo '<tr><th></th>'; foreach ($array as $x => $v) { echo "<th>{$x}</th>"; } echo "</tr>\n"; // Now for each item, compare it to every other item: foreach ($array as $nm => $y) { echo "<tr><th>{$nm}</th>"; foreach ($array as $x) { echo '<td>', $func($x, $y), '</td>'; } echo "</tr>\n"; } // Wrap up and we are done. echo "</table>\n";}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?