function resort_array($right, $left) { if ($right[0] == $left[0]) { $new_right = $right; shuffle($new_right); resort_array($new_right, $left); } else { foreach ($right as $key => $val) { get_template_part('templates/right', "slide-{$val}"); } } }
} //read file contents of json CONFIG file $config_file_string = file_get_contents('services.json'); //parse file contents into associative array $json = json_decode($config_file_string, true); //sort array by sort option $json = sort_array_by_field($json, $sort); //if there is a sort cookie present and $sort is default order by sort cookie if (isset($_COOKIE['sort_cookie'])) { $costum_order = unserialize($_COOKIE['sort_cookie']); if ($costum_order != NULL && !empty($costum_order)) { // //check if lengths are the same (only sort if logged in and see all services) if (count($costum_order) == count($json)) { // //only costum resort if default sort is chosen if ($sort == 'id_default') { $json = resort_array($json, $costum_order); } } } } //sort helper function (sorts $array by key value $field) function sort_array_by_field($array, $field) { $sortArray = array(); foreach ($array as $service) { foreach ($service as $key => $value) { if (!isset($sortArray[$key])) { $sortArray[$key] = array(); } $sortArray[$key][] = $value; }