arrays - Creat List From CSV file in PHP

I am new in PHP. I am working for make bulk message script for twillio. Its require number list like below
$subscribers = [
json_encode(['binding_type' => "sms", 'address' => "+910000000000"]),
json_encode(['binding_type' => "sms", 'address' => "+910000000000"])
];
I have data in csv file like below image
I am able to read the data from it like below
$csv = array_map('str_getcsv', file('data.csv'));
When I do
print_r($csv);
its showing data like
Array ( [0] => Array ( [0] => 910000000000) [1] => Array ( [0] => 910000000000) )
I am not getting idea how I can create list like below for use with twillio
$subscribers = [
json_encode(['binding_type' => "sms", 'address' => "+910000000000"]),
json_encode(['binding_type' => "sms", 'address' => "+910000000000"])
];
Let me know if anyone here can help me for do it. Thanks!
Answer
Solution:
Try this code
<?php
$csv = array_map('str_getcsv', file('data.csv'));
$subscribers = array();
foreach ($csv as $key => $value) {
$item = array();
$item['binding_type'] = "sms";
$item['address'] = "+".$value[0];
array_push($subscribers, json_encode($item));
}
?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: videoxxx
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.