poe Posted October 7, 2007 Share Posted October 7, 2007 can anyone see a better way of doing this... foreach($catAry as $ck => $cv) { $pn = (statCount($ck, 1, 'n') > 0) ? statCount($ck, 1, 'n') : 0; $pp = (statCount($ck, 1, 'y') > 0) ? statCount($ck, 1, 'y') : 0; $gn = (statCount($ck, 2, 'n') > 0) ? statCount($ck, 2, 'n') : 0; $gp = (statCount($ck, 2, 'y') > 0) ? statCount($ck, 2, 'y') : 0; $sn = (statCount($ck, 3, 'n') > 0) ? statCount($ck, 3, 'n') : 0; $sp = (statCount($ck, 3, 'y') > 0) ? statCount($ck, 3, 'y') : 0; $bn = (statCount($ck, 4, 'n') > 0) ? statCount($ck, 4, 'n') : 0; $bp = (statCount($ck, 4, 'y') > 0) ? statCount($ck, 4, 'y') : 0; $poeAry[] = array( 'category' => $cv, 'pn' => $pn, 'pp' => $pp, 'gn' => $gn, 'gp' => $gp, 'sn' => $sn, 'sp' => $sp, 'bn' => $bn, 'bp' => $bp, ); } Quote Link to comment https://forums.phpfreaks.com/topic/72152-shortening-down-some-code/ Share on other sites More sharing options...
Psycho Posted October 7, 2007 Share Posted October 7, 2007 Try this <?php $poeAry[] = array( 'pn' = ((statCount($ck, 1, 'n') > 0) ? statCount($ck, 1, 'n') : 0), 'pp' = ((statCount($ck, 1, 'y') > 0) ? statCount($ck, 1, 'y') : 0), 'gn' = ((statCount($ck, 2, 'n') > 0) ? statCount($ck, 2, 'n') : 0), 'gp' = ((statCount($ck, 2, 'y') > 0) ? statCount($ck, 2, 'y') : 0), 'sn' = ((statCount($ck, 3, 'n') > 0) ? statCount($ck, 3, 'n') : 0), 'sp' = ((statCount($ck, 3, 'y') > 0) ? statCount($ck, 3, 'y') : 0), 'bn' = ((statCount($ck, 4, 'n') > 0) ? statCount($ck, 4, 'n') : 0), 'bp' = ((statCount($ck, 4, 'y') > 0) ? statCount($ck, 4, 'y') : 0) ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/72152-shortening-down-some-code/#findComment-363765 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.