PHP code example of honeycomb / method-sort

1. Go to this page and download the library: Download honeycomb/method-sort library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

honeycomb / method-sort example snippets


class Person {
	public function __construct($firstname, $lastname) {
		$this->firstname = $firstname;
		$this->lastname  = $lastname;
	}

	public function getFirstName()
	{
		return $this->firstname;
	}

	public function getLastName()
	{
		return $this->lastname;
	}
}

$objects     = [
	'ms' => new Person('Matthew', 'Sahagian'),
	'mj' => new Person('Matthew', 'Jones'),
	'bt' => new Person('Brian', 'Tam')
];

$method_sort = new Honeycomb\MethodSort();

$method_sort->setOrder([
	'getFirstName' => 'asc',
	'getLastName'  => 'asc'
]);

uasort($objects, $method_sort);

array (
  'bt' =>
  Person::__set_state(array(
     'firstname' => 'Brian',
     'lastname' => 'Tam',
  )),
  'mj' =>
  Person::__set_state(array(
     'firstname' => 'Matthew',
     'lastname' => 'Jones',
  )),
  'ms' =>
  Person::__set_state(array(
     'firstname' => 'Matthew',
     'lastname' => 'Sahagian',
  )),
)