jimmyjamieson
7/16/2015 - 12:55 PM

Comparing arrays in Yii

Comparing arrays in Yii

$settings = CHtml::listData(GeneralSettings::model()->findAll("`group` = 'email'"), "setting", "value");
        $collectLogData = array(
            "emailServer" => $post["emailServer"],
            "emailPort"  =>  $post["emailPort"],
            "emailUsername" => $post["emailUsername"],
            "emailPassword" => $post["emailPassword"],
            "emailEncryption" => $post["encryption"],
            "emailAuth" => $post["emailAuthentication"],
        );
        // Compare posted data array with currently saved settings array, and remove key if no difference
        $compareData = array_diff($collectLogData, $settings);

        $logData = $compareData;
        $logList = '<br><br><ul class="list">';
        foreach ($logData as $key=>$value) {
            $logList .= '<li>' . $key . ': ' . $value . '</li>';
        }
        $logList .= '</ul>';