2014-01-30 4 views
-2

$test_data이라는 배열이 있는데 키 ['test_duration']을 업데이트하고 싶습니다. 그러나이 업데이트를 수행 할 수 없습니다. 다음과 같은 배열을 고려하십시오배열 키의 값이 업데이트되지 않는 이유는 무엇입니까?

Array 
(
    [0] => Array 
     (
      [test_id] => 1116 
      [test_name] => ques stats 
      [test_no_questions] => 50 
      [test_duration] => 28800 
     ) 

    [1] => Array 
     (
      [test_id] => 1112 
      [test_name] => Own Test 1 
      [test_no_questions] => 2 
      [test_duration] => 7200 
     ) 

) 

나는 다음과 같은 시도를하지만 잘 안 :

foreach ($test_data as $key => $value) { 
    $value[$key]['test_duration'] = ConvertTimeStampToTimeFormate($value['test_duration']); 
} 

을 나는이 조작 후 배열을 인쇄하는 경우, 그것은 이전과 같은 배열을 인쇄합니다. 여기에 어떤 문제가 있습니까?

+0

RTFM : http://www.php.net/manual/en/control-structures .foreach.php – CBroe

답변

3

업데이트 $의 test_data,

foreach ($test_data as $key => $value) { 
         $test_data[$key]['test_duration'] = ConvertTimeStampToTimeFormate($value['test_duration']); 
        } 
2

너는 또한 더 중첩 할 필요가있다. 대신

foreach ($test_data as $key => $value) { 
    $test_data[$key]['test_duration'] = ConvertTimeStampToTimeFormate($value['test_duration']); 
} 
0

사용이 같은 $ 값의

foreach ($test_data as $arr) 
{ 
    foreach($arr as $k=>$v) 
    { 
    $value[$k]['test_duration'] = ConvertTimeStampToTimeFormate($value['test_duration']); 
    } 
}