1
I have the following Array
with the relevant data applied:
- Card Number
- Month (Validity or Maturity)
- Year
I get this data from a API but in a "disorganized" way. I would like to treat these values to follow a specific pattern. I tried to use the function sort()
of php, but without success.
I receive them this way (disorderly/randomly)
Array
(
[0] => Array
(
[0] => 5522 8600 0000 0000
[1] => 2020
[2] => 09
)
[1] => Array
(
[0] => 09
[1] => 5522 8600 0000 0000
[2] => 2020
)
[2] => Array
(
[0] => 5522 8600 0000 0000
[1] => 20
[2] => 9
)
)
It is noticeable that ...
the values of the keys [0], [1] and [2] are different from others elements. What was meant to be:
- [0] = Card Number
- [1] = Month
- [2] = Year
Therefore, I would like to create/use a function in which it was possible to standardize them in this way:
Array
(
[0] => Array
(
[0] => 5522 8600 0000 0000
[1] => 09
[2] => 2020
)
[1] => Array
(
[0] => 5522 8600 0000 0000
[1] => 09
[2] => 2020
)
[2] => Array
(
[0] => 5522 8600 0000 0000
[1] => 9
[2] => 20
)
)
regardless of their positions...
Also worth mentioning
Which, according to this scenario, where the year of 2020 is shown with only 2 decimal places, ie, 20 there would be a conflict with the values of Month, but in the case of validity, to obtain the Month without knowing its position (besides receiving them in a disorderly way..)
Array
(
[0] => Array
(
["mes"] => 09
["cartao"] => 5522 8600 0000 0000
["ano"] => 20
)
)
However, because there are no "named" keys, simply create conditions, where:
- value less than or equal to 12 refers to the month
following the number of months we have in 1 year. Already
- greater than 12 refers to the year
With this I can obtain the respective values, the opposite of the Card number that only use the Algorithm Luhn to validate Credit/Debit card numbers that resolve!
This cannot occur, it is a serious project error that must be corrected in the backend aiming at a standardization of the data. It is serious because if you look for a record of the beginning of the century, for example, the possibility of data being indistinguishable.
– Augusto Vasques
Like this @Augustovasques ?
– gleisin-dev
has to make the return of this call uniform. Fix this in the forntend is gambiarra.
– Augusto Vasques
but my purpose is just fix in the back-end, I get these values so
desordenada
from an external API (another server) and order it to move to the front endordenada
of my project– gleisin-dev
The backend is an internal process. One of the internal processes of this php code (which is an internal process of your application) is this API in question that is not friendly to the developer because it does not ensure the consistency of the data because it does not present hierarchy and hegemonic structure in the responses to requests, which may imply situations where the information is indecipherable, the cited example of searches for records dating from the beginning of the century until 2012. This API is the one to be corrected or replaced.
– Augusto Vasques
@Augustovasques understood, the solution must come from the API right? So to get these values in an orderly way I would need to do what I needed to do? (unfortunately this is the only API so far that can provide this data..)
– gleisin-dev
That’s right. You can tell what the API is and provide a link to the function documentation.
– Augusto Vasques