Welcome Guest, Not a member yet? Register   Sign In
Exploding Array Elements... Using explode TWICE
#3

[eluser]richthegeek[/eluser]
WanWizard's code would result in every element being an array, mostly of length 1. This is probably a good thing though!

Two ways to make it work nicer/differently would be to use either strstr to check for a / before exploding, or array_pad to allow easy testing of element[1] without firing "Undefined var" notices.

Code:
$array = explode( ",", $str );
foreach( $array as $key=>$value ) $array[ $key ] = strpos( $value, "/" ) ? explode( "/", $value ) : $value;

Code:
$array = explode( ",", $str );
foreach( $array as $key=>$value ) $array[ $key ] = array_pad( explode("/",$value), 2, false );


Messages In This Thread
Exploding Array Elements... Using explode TWICE - by El Forum - 04-26-2010, 12:24 AM
Exploding Array Elements... Using explode TWICE - by El Forum - 04-26-2010, 12:38 AM
Exploding Array Elements... Using explode TWICE - by El Forum - 04-26-2010, 12:48 AM
Exploding Array Elements... Using explode TWICE - by El Forum - 04-26-2010, 01:08 AM
Exploding Array Elements... Using explode TWICE - by El Forum - 04-26-2010, 01:12 AM
Exploding Array Elements... Using explode TWICE - by El Forum - 04-26-2010, 01:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB