Skip to content
Advertisement

How to sort an Array using If in PHP

I have the following Array which contains data such as: Card, Month and Year. However, I receive it in a disorganized way and I would like to treat these values to follow the pattern. No Card, Year and Month or Month, Card and Year. I tried to use the sort() functions of php, but without success!

JavaScript

I would like to create a function in which the Array is organized as follows:

JavaScript

Then comes the point of conditions, if as the Array the year 2020 is defined with only 2 decimal places, that is, 20 (19, 20, 21, 22, 23, …) I would check if the value does not is greater than 12, following the number of months we have in 1 year, knowing this, to identify the year in this Array, I would apply another validation to check if the value is greater than 12 and if it has 2 or 4 digits, however I can’t apply it in any way!

Thank you very much in advance!

Advertisement

Answer

As per your comment you can go with this solution:

JavaScript

Output: https://3v4l.org/BZIFX

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement