Link to home
Start Free TrialLog in
Avatar of denny3d
denny3d

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Tomeeboy
Tomeeboy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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 ;)