note 83049 added to types.comparisons

From: Date: Thu, 08 May 2008 07:48:41 +0000
Subject: note 83049 added to types.comparisons
Groups: php.notes 
Request: Send a blank email to php-notes+get-139168@lists.php.net to get a copy of this message
Universal comparison test. <?php $tests = array(); $tests['=='] = create_function('$a, $b', 'return $a==$b;'); $tests['==='] = create_function('$a, $b', 'return $a===$b;'); $tests['!='] = create_function('$a, $b', 'return $a!=$b;'); $tests['<>'] = create_function('$a, $b', 'return $a<>$b;'); $tests['!=='] = create_function('$a, $b', 'return $a!==$b;'); $tests['<'] = create_function('$a, $b', 'return $a<$b;'); $tests['>'] = create_function('$a, $b', 'return $a>$b;'); $tests['<='] = create_function('$a, $b', 'return $a<=$b;'); $tests['>='] = create_function('$a, $b', 'return $a>=$b;'); $comparison = array(); $comparison['TRUE'] = true; $comparison['FALSE'] = false; $comparison['1'] = 1; $comparison['0'] = 0; $comparison['-1'] = -1; $comparison['3,14'] = pi(); $comparison['"1"'] = '1'; $comparison['"0"'] = '0'; $comparison['"-1"'] = '-1'; $comparison['NULL'] = null; $comparison['array()'] = array(); $comparison['"php"'] = 'php'; print '<h1>PHP version '.PHP_VERSION.' type comparison tables</h1>'; foreach ($tests as $test=>$function) { print "<h2>Comparisons with $test</h2>"; print "<table border='1'>"; print "<tr>"; print "<th>&nbsp;</th>"; foreach (array_keys($comparison) as $name) { print "<th>$name</th>"; } print "</tr>"; foreach ($comparison as $arg_1_name => $arg_1_value) { print '<tr>'; print "<th>$arg_1_name</th>"; foreach ($comparison as $arg_2_value) { print '<td>'; print $function($arg_1_value, $arg_2_value)==true ? '<span style="color:#00F;">TRUE</span>' : '<span style="color:#F00;">FALSE</span>'; print '</td>'; } print "</tr>"; } print "</table>"; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 212.98.183.3 ---- Manual Page -- http://www.php.net/manual/en/types.comparisons.php Edit -- https://master.php.net/note/edit/83049 Del: integrated -- https://master.php.net/note/delete/83049/integrated Del: useless -- https://master.php.net/note/delete/83049/useless Del: bad code -- https://master.php.net/note/delete/83049/bad+code Del: spam -- https://master.php.net/note/delete/83049/spam Del: non-english -- https://master.php.net/note/delete/83049/non-english Del: in docs -- https://master.php.net/note/delete/83049/in+docs Del: other reasons-- https://master.php.net/note/delete/83049 Reject -- https://master.php.net/note/reject/83049 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139168) next »