Digital Marketing

Example of Reduce repetition by loop

Example of Reduce repetition by loop

$item[ 'id' ] = $_POST[ 'id' ];
$item[ 'name' ] = $_POST[ 'name' ];
$item[ 'mail' ] = $_POST[ 'mail' ];
$item[ 'qq' ] = $_POST[ 'qq' ];
If there is a logic similar chunk of code, only one or two places of changes, it can often be replaced by loop:
foreach ( array( 'id', 'name', 'mail', 'qq' ) as $key ) {
$item[ $key ] = $_POST[ $key ];
}

Comments

Popular posts from this blog

Make online money from the Internet