php - explode string and set key for array with text that is in front of the delimiter? -
is there way take input this:
| testing==one 2 3 | setting==more testing |
and this
array['testing'] = "one 2 three"; array['setting'] = "more testing"
right i'm exploding string , setting array numbered index, i'd user able enter items in order , able use array keys first value.
function get_desc_second_part(&$value) { list(,$val_b) = explode('==',$value); $value = trim($val_b); }
thanks!
something this? pipes adds maybe needless complexity (separator new lines):
$arr = array(); foreach (explode('|', $str_input) $line) { $l = explode('==', trim($line)); if (isset($l[1])) $arr[$l[0]] = $l[1]; } print_r($arr); /* array ( [testing] => 1 2 3 [setting] => more testing ) */
Comments
Post a Comment