search and replace value in PHP array

前端 未结 9 1054
一生所求
一生所求 2020-12-08 19:43

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:

         


        
9条回答
  •  猫巷女王i
    2020-12-08 20:09

     $green_key = array_search('green', $input); // returns the first key whose value is 'green'
    

    $input[$green_key] = 'apple'; // replace 'green' with 'apple'

提交回复
热议问题