2

new to the stackoverflow community, so do be forgiving if I've done anything incorrect. As I'm an amateur in coding in php, I'm currently facing a difficulty in multi dimensional arrays.

Currently, I have this array being returned to me.

Array(
    [trialID] => 1
    [trialMixedArray] => 1,2,3,4,5,6
    [trialStatus] => active
    [trialAddedDate] => 2017-11-13 09:56:03
)

How do I split the trialMixedArray and return it to the original array so that it becomes formatted to be like the following result:

Array(
    [trialID] => 1
    [trialMixedArray] => Array(
                               [0] => 1
                               [1] => 2
                               [2] => 3
                               [3] => 4
                               [4] => 5
                               [5] => 6
    [trialStatus] => active
    [trialAddedDate] => 2017-11-13 09:56:03
)

Thanks for the help in advance! Cheers! :)

3 Answers 3

2

Use explode function, which splits string to array. Manual.

$results['trialMixedArray'] = explode(',', $results['trialMixedArray']);

Sign up to request clarification or add additional context in comments.

Comments

0

you can try something like this

$finalArray = [];
fetchItems($array_variable) {
  foreach($array_variable as $item){
    if(is_array($item) {
      fetchItems($item);
    } else {
      $finalArray[] = $item;
    }
  }
}

fetchItems($originaArray);

Comments

0

Use explode function to split any string based on a key.

The syntax is explode('key',string);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.