-6

I'm migrating a project from Java code to PHP, but some Java code is Alien to me. May i know what this Java code does? And how can i "interpret" this in PHP?

//contentList array
contentsList.sort((ClassBook c1, ClassBook c2)->c1.getClassDate().compareTo(c2.getClassDate()));

Thank You!

Eljay
  • 21
  • 4
  • 1
    It quite literally sorts the list by comparing `c1` to `c2` using a custom comparator function, which is probably implemented in `ClassBook` class. – nbokmans May 17 '18 at 08:53
  • `compareTo` is as the name suggests, comparing two values. In your case it compares 2 dates. One is maybe earlier than the other and vice versa – Lino May 17 '18 at 08:54
  • 1
    If you just type 'java compareTo' in google you find really good answers in just the first few links. The javadoc is always a good place to start. – findusl May 17 '18 at 09:00
  • What is the possible approach in PHP? – Eljay May 17 '18 at 09:01
  • @Eljay that may even be another research worth, as mentioned before, just google: *Php compare dates* – Lino May 17 '18 at 09:18

1 Answers1

1

Compares ClassBook c1 with the ClassBook c2 for order. Besides, it looks the date field for comparison. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Hatice
  • 874
  • 1
  • 8
  • 17