2014-01-19 37 views
0

一個數組中的值我有這樣的數組:更新在PHP

 
Array 
(
    [messagecount] => 1 
    [messages] => Array 
     (
      [0] => Array 
       (
        [status] => returnCode 
        [messageid] => messageId 
        [to] => to 
        [client-ref] => client-ref 
        [remainingbalance] => remaining-balance 
        [messageprice] => 0.01 
        [network] => network 
        [errortext] => error-message 
       ) 

     ) 

) 

我想要做的是,我想在來代替值「messageprice」]它是默認設置爲0.01我想把它做成0.02或者其他我想要的。

編輯後,我想在同一個數組中更新值。我想這個結果

 
Array 
(
    [messagecount] => 1 
    [messages] => Array 
     (
      [0] => Array 
       (
        [status] => returnCode 
        [messageid] => messageId 
        [to] => to 
        [client-ref] => client-ref 
        [remainingbalance] => remaining-balance 
        [messageprice] => 0.02 
        [network] => network 
        [errortext] => error-message 
       ) 

     ) 

) 

回答

2

那麼你可以像

$yourarray['messages'][0]['messageprice'] = '0.02'; 

Demo

+0

對不起,如果我不清楚。我想替換同一個數組中的['messageprice']值 –

+2

@ProfessorHaseeb這就是上面的代碼所做的...(儘管我不會引用該值)。你甚至嘗試過嗎? –

+1

解決方案做好工作 – phpCore