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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -