0

If you have a multidimensional array, such as follows:

$array = array(
    'name' => 'user',
    'values' => 'one, two, three',
    'params' => array('three');    
);

How can you split 'values' key so it then becomes an array on its own?

i.e

$array = array(
    'name' => 'user',
    'values' => array('one', 'two', 'three'),
    'params' => array('three');    
);
1
  • Your title is misleading. Actually you have a string that you want to split ('one, two, three' is just a string). Commented Feb 6, 2011 at 18:41

2 Answers 2

5
$array['values'] = explode(', ', $array['values']);
Sign up to request clarification or add additional context in comments.

Comments

2

If you wish to run this check on all the fields and not just the values one:

foreach($array as &$value)
{
    if (!is_array($value))
    {
        $value = explode(', ', $value);
    }   
}
unset($value);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.