lundi 25 avril 2016

How to format a multidimensional/nested array so it only returns the integer and not the column heading?

Im trying to create a nested array when retrieving data from a mysql database that looks like this:

array:2 [▼
  0 => array:3 [▼
    "screen_name" => "Audi"
    "id" => "A1"
    0 => array:3 [▼
      0 => 331
      1 => 350
      2 => 400
    ]
  ]
  1 => array:3 [▼
    "screen_name" => "BMW"
    "id" => "X2"
    0 => array:1 [▼
      0 => 1500
    ]
  ]
]

Currently my array returns data in this format:

array:2 [▼
  0 => array:2 [▼
    "screen_name" => "Audi",
    "id" => "A1",
    0 => array:3 [▼
      0 => {#247 ▼
        +"followers_count": "331"
      }
      1 => {#248 ▼
        +"followers_count": "350"
      }
      2 => {#249 ▼
        +"followers_count": "400"
      }
    ]
  ]
  1 => array:2 [▼
    "screen_name" => "BMW",
    "id" => "X2",
    0 => array:1 [▼
      0 => {#250 ▼
        +"followers_count": "1500"
      }
    ]
  ]
]

Very similar but I need to remove the +"followers_count" in the nested part of the array and only return the integer.

My query is:

$users = DB::table('users')->distinct('social_id')->get();
foreach ($users as $user)
{
    $user_followers = DB::table('user_followers')->where('social_id', $user->social_id)->select('followers_count')->get();
    $records[] = array(
                                                                  'screen_name'   => $user->screen_name,
                                                                  $user_followers,
    );
}

How would I go about stripping out the +"followers_count" in the nested array and just return the integer.

Note: Im using Laravel 5.1 and mysql



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire