Jump to content

[SOLVED] Simplifying Logical Expressions


TankedShark

Recommended Posts

They're a little unwieldy, but they work. Can they be made simpler?

 

<?php

if ( ($grid[$startrow - 1][$startcolumn] != '') && ($grid[$startrow - 1][$startcolumn] != '#') )

if ( ($grid[$startrow + count($word)][$startcolumn] != '') && ($grid[$startrow + count($word)][$startcolumn] != '#') )

if ( ($grid[$startrow + $letter][$startcolumn]) == '' || ($grid[$startrow + $letter][$startcolumn] == $word[$letter]) )

?>

Link to comment
https://forums.phpfreaks.com/topic/135495-solved-simplifying-logical-expressions/
Share on other sites

eh. well, I mean, you can do this:

 

<?php
$array = array('','#');
if (!in_array($grid[$startrow - 1][$startcolumn], $array))

if (!in_array($grid[$startrow + count($word)][$startcolumn], $array))

if ( ($grid[$startrow + $letter][$startcolumn]) == '' || ($grid[$startrow + $letter][$startcolumn] == $word[$letter]) )

?>

 

IMO it's not really 'simpler' but I guess it's a few less chars of coding...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.