I have a string ($c) that contains a comma-separated list of settings. Some settings are stand-alone, while others require a sub-setting that is separated by an equal sign.
Example:
$c = "title,author,tax=taxonomy_A,tax=taxonomy_B,date";
I need to parse this string into a multidimensional array ($columns) that outputs like this:
$columns = array(
[0] => array( 'title', '' ),
[1] => array( 'author', '' ),
[2] => array( 'tax', 'taxonomy_A' ),
[3] => array( 'tax', 'taxonomy_B' ),
[4] => array( 'date', '' )
)
I have tried this:
$c = "title,author,tax=taxonomy_A,tax=taxonomy_B,meta=custom_field_key";
$c = explode( ',', $c );
$columns = array( explode( '=', $c ) );
But that just returns this:
$columns = array(
[0] => array( 'Array' )
)
What am I missing here? Should the second explode be replaced with a different function?
Thanks in advance!
1 Answer