How can I write in PHP a function that modifies an array?

前端 未结 3 805
悲哀的现实
悲哀的现实 2021-02-14 04:33

I would like to have a function that takes an array as input and changes some values of the array (in my case the array is $_SESSION but I think it does not really maters).

3条回答
  •  星月不相逢
    2021-02-14 04:52

    function change_array() {
    
         global $x; /*this will tell the function to work on the array 'x' out of the function itself.*/
         $x[0] = 100;
    
    }
    

提交回复
热议问题