0
I’m having a really hard time drawing a array
in PHP
with the following data coming from an object JSON
, no, it does not come from a database SQL query.
Example of JSON
:
[
{
"data": {
"ID": "349",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"source": "Google",
"user_registered": "2018-03-22 12:46:35",
"user_activation_key": "",
"user_status": "0",
"display_name": "Antonio Carlos Braga"
},
"ID": 349,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
},
{
"data": {
"ID": "292",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"source": "Google",
"user_registered": "2018-03-21 02:19:11",
"user_activation_key": "",
"user_status": "0",
"display_name": "Adriana Cristina Alves da Silva"
},
"ID": 292,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
},
{
"data": {
"ID": "196",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"source": "Facebook",
"user_registered": "2018-03-20 14:28:58",
"user_activation_key": "",
"user_status": "0",
"display_name": "Adriana Fernandes de oliveira"
},
"ID": 196,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
},
{
"data": {
"ID": "286",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"source": "Google",
"user_registered": "2018-03-21 01:19:53",
"user_activation_key": "",
"user_status": "0",
"display_name": "Alexandre Ramos de Campos"
},
"ID": 286,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
},
{
"data": {
"ID": "225",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"source": "Google",
"user_registered": "2018-03-20 17:55:09",
"user_activation_key": "",
"user_status": "0",
"display_name": "Alex miguins de lima"
},
"ID": 225,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
},
{
"data": {
"ID": "318",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"source": "Google",
"user_registered": "2018-03-21 14:35:38",
"user_activation_key": "",
"user_status": "0",
"display_name": "Alexandra Alves Ferreira"
},
"ID": 318,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
},
{
"data": {
"ID": "188",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"source": "Google",
"user_registered": "2018-03-20 13:21:28",
"user_activation_key": "",
"user_status": "0",
"display_name": "Analucia c g pedreira"
},
"ID": 188,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
},
{
"data": {
"ID": "216",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"source": "Facebook",
"user_registered": "2018-03-20 16:56:12",
"user_activation_key": "",
"user_status": "0",
"display_name": "ANDREZA AP TOLEDO"
},
"ID": 216,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
},
{
"data": {
"ID": "299",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"source": "Google",
"user_registered": "2018-03-21 05:39:16",
"user_activation_key": "",
"user_status": "0",
"display_name": "angela maria de queiroz"
},
"ID": 299,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
},
{
"data": {
"ID": "291",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"source": "Google",
"user_registered": "2018-03-21 02:15:56",
"user_activation_key": "",
"user_status": "0",
"display_name": "Angelica dos Santos Marques"
},
"ID": 291,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
},
{
"data": {
"ID": "224",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"user_registered": "2018-03-20 17:47:14",
"user_activation_key": "",
"user_status": "0",
"display_name": "Adilson Nicanor de Assis"
},
"ID": 224,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
},
{
"data": {
"ID": "190",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"source": "Facebook",
"user_registered": "2018-03-20 13:39:58",
"user_activation_key": "",
"user_status": "0",
"display_name": "António Carlos Bomfim Barros"
},
"ID": 190,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
},
{
"data": {
"ID": "359",
"user_login": "###",
"user_pass": "###",
"user_nicename": "###",
"user_email": "###",
"user_url": "",
"source": "Google",
"user_registered": "2018-03-23 01:23:08",
"user_activation_key": "",
"user_status": "0",
"display_name": "Marizete De Souza Lobato"
},
"ID": 359,
"caps": {
"subscriber": true
},
"cap_key": "gc_capabilities",
"roles": [
"subscriber"
],
"allcaps": {
"read": true,
"level_0": true,
"subscriber": true
},
"filter": null
}
]
What translated into a table would be:
| Fonte | Data de cadastro |
|----------|------------------|
| Google | 21/03/2018 |
| Google | 22/03/2018 |
| Facebook | 21/03/2018 |
| Facebook | 22/03/2018 |
| Google | 23/03/2018 |
| Facebook | 21/03/2018 |
| Google | 21/03/2018 |
| Google | 22/03/2018 |
Counting manually I know that on 21/03/2018 I had 2 Google registrations and 2 Facebook registrations, 22/03/2018 I had 1 Google registration and 1 Facebook registration, and so on.
I would like to generate one array
which I believe is associative to generate a table like this after a loop
:
| Fonte | Data de cadastro | Total de cadastros |
|----------|------------------|--------------------|
| Google | 21/03/2018 | 2 |
| Facebook | 21/03/2018 | 2 |
| Facebook | 22/03/2018 | 1 |
| Facebook | 22/03/2018 | 1 |
| Google | 23/03/2018 | 1 |
I also know that this sum can be obtained with a function to sum the values of the array
but I can’t "draw" that array
.
Is that in the bank? tried to group? shows how the array is?
– rray
It comes in a JSON Object that I can easily in a loop and that I want to convert to array, but no, it doesn’t come from an SQL query
– Danilo P. da Silva
@Danilop.So could you paste this JSON that you receive? At least some of it (if it’s big enough) to see the format.
– Israel Merljak
I updated the question ;)
– Danilo P. da Silva
Your
JSON
is not valid. Comma is missing and comma is wrong. Is this really what is coming from the bank ? Error to thedecode
none ? You’re putting the "true"$array = json_decode($json, true);
?– rbz
I had already cleaned the JSON so that it would not be full of useless information from Respse. This is the JSON answer via Postman, no result in PHP with json_decode()
– Danilo P. da Silva
You want to "group" the same records in the array, with a counter... that’s it ?
– rbz
That, but separated by date. I thought about doing this through an array to generate a table at the end. Type, I get in each item of the JSON object: id, email, name, registration date, traffic source. And I need to compile in a table that on day X I received Y Google Signups, Z Facebook Signups.
– Danilo P. da Silva
According to this JSON.. not all records have the data you want.. Not all records have the specified Source.
– Israel Merljak
This JSON is just an example, I can edit and put the source where it is missing. JSON is giant, I just edited the final result to get next to logic. I will edit again.
– Danilo P. da Silva