I have a comma separated list of numbers from a post variable, which outputs e.g:
123, 456, 789, 101, 112
// Number comma space
I then use the following code to process these IDs individually:
$id_string = $_POST['ids'];
$id_array = array_map('trim', explode(',', $id_string));
foreach ($id_array as $value){
$url = 'http://myserver.com';
$data = array('a' => $value, 'reStock' => 'true');
$get = array();
foreach($data as $k => $v){
$get[] = $k . '=' . urlencode($v);
}
$get = implode('&', $get);
$opts = array('http' =>
array(
'method' => 'GET',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $get
)
);
$context = stream_context_create($opts);
$mxsendstock = file_get_contents($url, false, $context);
}
After testing all afternoon, I can't get the foreach to work - nothing happens. The only possible cause I can see is if I'm handling the comma-separated list correctly.
Any ideas?