Logic gate simulation in PHP