transform an array into multidimensional array php

hi EE

i have an array like this

Array
(
    [0] => 1302 11022009 132V4
    [1] => 1302 11022009 132V4
}

can i trasform this array into this?

Array
(
    [0] => Array
              (
                 [0] =>1302
                 [1] =>11022009
                 [2] =>132V4
              )
    [1] => Array
              (
                 [0] =>1302
                 [1] =>11022009
                 [2] =>132V4
              )
}

Array
(
    [0] => 1302 11022009 132V4
    [1] => 1302 11022009 132V4
}

[0] => Array
denny3dAsked:
Who is Participating?
 
TomeeboyConnect With a Mentor Commented:
Yep :)

foreach ($array as $value) {
     $new_array[] = explode(" ", $value);
}
0
 
TomeeboyCommented:
Further explanation.... The explode() function will create an array out of your original value, using the spaces as separation points.  So, you loop through the original array, exploding each value into its own array.  In the process, you're inserting each exploded array into one master array, creating the multi-dimensional array that you wanted.

If you wanted to put everything back together in its original form:

<?php

foreach ($new_array as $value) {
     $restored_array[] = implode(" ", $value);
}

?>

Which would give you back your original array of values separated by spaces.
0
 
TomeeboyCommented:
Glad this worked, but any particular reason why you feel the solution is only worth a B?  I provided exactly what you asked for and even the code to do the reversal.

Just curious if I missed something ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.