Jump to content

shortening down some code...


poe

Recommended Posts

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,

);

 

}

Link to comment
https://forums.phpfreaks.com/topic/72152-shortening-down-some-code/
Share on other sites

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)
);
?>

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.