TRUE); for ( $i = 0; $i < count($w_array); $i++ ) { foreach ( $dp as $weight => $value ) { if ( $value === TRUE ) { $dp[$weight+$w_array[$i]] = TRUE; } } } $w_target = $w_total / 2; if ( isset($dp[$w_target]) && ($dp[$w_target] === TRUE) ) { echo 'possible'.PHP_EOL; } else { echo 'impossible'.PHP_EOL; }