PHP Codeigniter, should i set array defaults or simply use if.. else statements repeatedly

So I am utilizing codeigniter.

To allow reusability of code i have a number of functions in my model which get different things.

e.g get_details, get_features, get_products

I then have a function called get_all which calls all these methods, so If i want i can get them all but otherwise i can use them individually.

So I have my data, and I pass it to my view. My view loops through each establishment and displays various data in a table row.

At present I use if.. else statements to discern if a value is empty for example.
So if an establishment has not had its features added yet I use:

if(!empty($features['feature1'])){//DO STUFF e.g output 'YES'}

Anyway, my views code is no getting rather long and complicated because essentially for each and every key of each array returned using get_all I am using an if..else statement to output a “-” if it is not set.

It works, it just seems repetitive.

The work around I thought of is to simply set a default array whereby everything is by default set to “-”, then if the data does exist it is overwritten, but then I just have to write/initiate a large default array..

So my question is not a life threatening one, nor is it particularly hard.. I am simply curious as to how one achieves such functionality without ugly code.


Leave a Reply


Hire Me
Follow Me!
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.