1
I have a variable that returns a certain number that is correct.
Example:
$cc = "52532005536430673";
My question is: how do I verify that this number is present in a JSON? As below:
{
"testadas": {
"52532005536430673|04|2023|869": {
"cc": "52532005536430673",
"dados": "\ud83c\udde7\ud83c\uddf7",
"status": "Reprovada",
"data_hora": "02-09-2018 20:45:13",
"retestada": false
}
}
}
In this case it is present in the "CC" and always want to check if the number is present in the "CC".
I think this would not work properly, because I have several cc fields in json, and I need to check the variable!
– MR. B4RCODE
Could show an example of a json that has more than one cc?
– André Araujo
https://ghostbin.com/paste/bfqpj !
– MR. B4RCODE
So, the way I introduced him, he’s going through every item of json. First he will check whether in the key "52532005536430673|04|2023|869" there is the cc field, and then whether in the key "52532005536400673|04|2023|869" there is this field in it. There is no problem that there is more than one "cc" field, since it will only validate the context of each key in each json item.
– André Araujo
Okay, but you end up with the same "error" that I told Gabriel, the foreach returns nothing!
– MR. B4RCODE
The first json_decode parameter must be a string and not a file. To get the value that is in the file you want can be done this way: json_decode(file_get_contents($file2),1);
– André Araujo
Okay, I was able to solve it, but now for me to echo the info, like the data for example, would this be it?: echo $item["$card"]->data;
– MR. B4RCODE
It would look like this: echo $item['data']; it will not be necessary to pass the card ID to print the other columns inside the foreach.
– André Araujo
It worked, thanks partner! !
– MR. B4RCODE