Array_Pluck Conditional

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 26, 2012   (RSS)

Re: [Perchpole] Array_Pluck Conditional

By Jason - July 25, 2012

Hi Perch,

Because the field will always exist in each record, even if empty, array_pluck will always return 1 array element for each record passed into it.

You can get around this by using array_filter() to get rid of any empty values like this:

<?php if(count(array_filter(array_pluck($branchRecords, 'attachments'))) > 0): ?>

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Array_Pluck Conditional

By Perchpole - July 26, 2012

Perfect!

Thanks, Jason

:0)

Perch