I have been looking at this problem for quite sometime and finally created my answer.
I have three array keys that will output different values. The condition of each key will either be true or NULL and this is what I am testing for my array is simple and looks like this.
$a = array();
$a['Font'] = logix::templateParams('googleWebFont');
$a['Font2'] = logix::templateParams('googleWebFont2');
$a['Font3'] = logix::templateParams('googleWebFont3');
I wanted to create output dependent on the collective condition of all three keys for example if one key is null then the output would be different then If I had 2 keys 'NULL'. I managed to create a simple switch which covered the range of values that I needed to cover my code looks like this.
$a = array();
$a['Font'] = logix::templateParams('googleWebFont');
$a['Font2'] = logix::templateParams('googleWebFont2');
$a['Font3'] = logix::templateParams('googleWebFont3');
switch (TRUE){
// No font selected
case $a['Font'] == NULL && $a['Font2'] == NULL && $a['Font3'] == NULL:
echo 'nothing';
break;
// First googlefont selected only
case $a['Font'] && $a['Font2'] == NULL && $a['Font3'] == NULL:
echo 'one';
break;
// Second googlefont selected only
case $a['Font2'] && $a['Font'] == NULL && $a['Font3'] == NULL:
echo 'two';
break;
// Third googlefont selected only
case $a['Font3'] && $a['Font2'] == NULL && $a['Font'] == NULL:
echo 'three';
break;
// and Continues to cover another 10 more states.......
So far this works fine and covers each possible variation that I need to cover. I was wondering if there was a more flexible way to do this. For example if I wanted to add another array value and compare the condition of the collective then this solution is not flexible enough to do so. I would have to completely re-write the case of the switch although this is unavoidable is there a more efficient way of doing this. Im completely new to PHP but I have been read a little on OOP and I just wondered what would be the OOP way of doing this. To be more clear of what I am trying to achieve.
// 1. collect the array keys
// 2. evaluate keys and check for certain conditions
// 3. output based on conditions
Is there a more flexible way of doing this?
regards
w9914420