0

To pass a group of checked checkbox values from a modal to a parent form, I send them to a hidden field.

This works well and is currently, as an example, returned in the format below

<input type="hidden" value="Mon, Wed, Sat" name="days">

What I need is to get an apostrophe seperated list in an array like this,

$days = array('Mon', 'Wed', 'Sat');   // currently static

from my hidden field here..

$days = Input::get('days'); // days selected in checkboxes
Cœur
  • 32,421
  • 21
  • 173
  • 232
user3189734
  • 645
  • 1
  • 7
  • 23

3 Answers3

1

Use explode():

$days = explode(', ', Input::get('days'));

http://php.net/manual/en/function.explode.php

mopo922
  • 6,039
  • 3
  • 25
  • 31
1

Use explode method()

explode() Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter.

Refrence

 $string ="Mon, Wed, Sat";
 $strngarray =  explode(',', string );  

In your case

$days = explode(', ', Input::get('days');
A.B
  • 17,478
  • 3
  • 28
  • 54
1

The function explode() should do this in php.

$values = 'value1, value2, value3';
$arrayOfValues = explode(', ', $values);
print_r($arrayOfValues);
Onema
  • 6,423
  • 11
  • 61
  • 97
Justjyde
  • 328
  • 1
  • 3
  • 13