Skip to content

Instantly share code, notes, and snippets.

@wlarch
Created October 4, 2020 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wlarch/b2f8612d1cad0c5c07c2aa97811c10ef to your computer and use it in GitHub Desktop.
Save wlarch/b2f8612d1cad0c5c07c2aa97811c10ef to your computer and use it in GitHub Desktop.
<?php
require "StringHelper.php";
$helper = new StringHelper();
$categories = [];
$news = new stdClass();
$news->names = ["fr" => "Actualités", "en" => "News"];
$categories[] = $news;
$sports = new stdClass();
$sports->names = ["fr" => "Sports", "en" => "Sports"];
$categories[] = $sports;
$home = new stdClass();
$home->names = ["fr" => "Accueil", "en" => "Home"];
$categories[] = $home;
$events = new stdClass();
$events->names = ["fr" => "Événements", "en" => "Events"];
$categories[] = $events;
$special = new stdClass();
$special->names = ["fr" => "Spécial", "en" => "Special"];
$categories[] = $special;
// Result alphabetically sorted in french : Accueil, Actualités, Événement, Spécial, Sports
// Result alphabetically sorted in english : Events, Home, News, Special, Sports
// Original order
var_dump($categories);
$helper->alphabeticalCompareArrayByKey($categories, 'names', 'fr');
// Alphabetical order (french) by names
var_dump($categories);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment