Jump to content

Beginner: explode array into multidimensional array


mac_gabe

Recommended Posts

Hi, I'm trying to explode an array into a multidimensional array using <br /> tags as splitters but just can't get the syntax right! I can do lines of the array one by one, but not the whole lot at once. I'd really appreciate a quick example of an explode inside an array.

 

$myarray looks something like this with print_r:

(
    [0] => 
    [1] => some_html<br />some_html<br />some_html<br />
    [2] => some_html<br />some_html<br />some_html<br />
    [3] => some_html<br />some_html<br />some_html<br />
)

 

and I want to turn it into this:

(
    [0] => 
    [1] =>
    	[0]some_html
    	[1]some_html
    	[2]some_html
    [2] => 
    	[0]some_html
    	[1]some_html
    	[2]some_html
    [3] =>
    	[0]some_html
    	[1]some_html
    	[2]some_html
)

 

I've tried this

$myarray = explode ("<br />", $myarray);

but it doesn't work …

 

It doesn't matter too much if there's are a few empty lines in the array from the final <br /> tags.

 

Many thanks, as ever, for any help.

OK I've done it with a for loop

$original_array_count= count($original_array);
for ($u=1; $u < $original_array_count; $u++) {
   $new_array[$u] = explode('<br />', $original_array[$u]);
}
print_r ($new_array);

 

I thought maybe there was a simpler way of doing it but I guess this works fine.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.