php - Do something with part of array, then reinsert it back into array? -
i creating array such, splitting string every -:
$array = explode('-', $mystring); i know can implode array 1 string, eg:
$mystring = implode('-', $array); but first need 3rd array element , reinsert array before re-concatenating it. here bit stuck - cant find resources showing online.
can point me in right direction?
you can access third element , reinsert array before imploding
$string = "foo-bar-foo2-bar2"; $array = explode("-", $string); $third = "something else"; $array[2] = $third; $string = implode("-", $array); print($string); results
foo-bar-something else-bar2
or can directly edit entry
$array[2] = "something else"
Comments
Post a Comment