Phrasing a long string to a 2d array PHP -
i have long string "123~456!!!789~012!!!345~678!!!901~234!!!567~890!!!1234~5678". have used types of delimiter in string ~ , !!! . can suggest me efficient way explode(split) string 2d array. example:
$txt = "123~456!!!789~012!!!345~678!!!901~234!!!567~890!!!1234~5678".
the 2d array after exploding/splitting.
array[0][0] = 123 ; array[0][1] = 456 ; array[1][0] = 789 ; array[1][1] = 012 ; array[2][0] = 345 ; array[2][1] = 678 ; array[3][0] = 901 ; array[3][1] = 234; array[4][0] = 567 ; array[4][1] = 890; array[5][0] = 1234 ; array[5][1] = 5678;
thanks. :)
this takes:
foreach(explode("!!!",$txt) $key => $subarray) { $array[$key] = explode("~",$subarray); } print_r($array);
quick , efficient, , you'll two-dimensional array.
Comments
Post a Comment