geetpurwar
1 year ago

DB Builder Query

Posted 1 year ago by geetpurwar

Hi,

I am not able to take value of variable outside. Let me know of what I am doing wrong?

$sentArray = array(); //Match if existing Subscriber has already been sent the message

array_push($sentArray, 0);

$query = \DB::table('subscribers');

$query
->select('id', 'endpoint', 'publicKey', 'authToken')
->where('website_id', $websiteId)
->orderBy('id')->chunk(200, function($subscribers) use($sentArray){
    foreach($subscribers as $subscriber){
        array_push($sentArray, $subscriber->id);
    }
});

dd($sentArray);

Result is always this:

array:1 [▼
  0 => 0
]

Please sign in or create an account to participate in this conversation.