How to Remove Empty Objects From Array In CakePHP

Author - Webner

In CakePHP, to remove empty or ‘false’ values from an Array, use CakePHP’s static ‘filter’ method contained in ‘Hash’ class:

$sampleArray =
 [
    ,
    false,
    true,
    0,
    ['one, 'two, 'three’]
]
$sampleArray = Hash::filter($sampleArray);

Here’s the array after filter method call:

$sampleArray =
 [
    true,
    0,
    ['one, 'two, 'three’]
]

 

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Web development or any other software development assistance please contact us at webdevelopment@webners.com

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *