title: search and replace value in PHP array
body: <p>I was looking for some standard PHP function to replace some value of an array with other, but surprisingly I haven't found any, so I have to write my own:</p>
  
  <pre><code>function array_replace_value(&amp;$ar, $value, $replacement)
  {
      if (($key = array_search($ar, $value)) !== FALSE) {
          $ar[$key] = $replacement;
      }
  }
  </code></pre>
  
  <p>But I still wonder - <strong>for such an easy thing there must already be some function for it</strong>! Or maybe much easier solution than this one invented by me?</p>
  
  <p>Note that this function will only do one replacement. I'm looking for existing solutions that similarly replace a single occurrence, as well as those that replace all occurrences.</p>