如何访问值形式数组

问题描述 投票:-1回答:1

请在下面找到包含php中的数组

    $data = array ( 'questions' => array ( 1 => 
array (
  'section_id' => '61',
  'questionid' => '2035',
  'time_spent' => '0',
),
2 => 
array (
  'section_id' => '61',
  'questionid' => '2036',
  'time_spent' => '0',
),
3 => 
array (
  'section_id' => '61',
  'questionid' => '2037',
  'time_spent' => '0',
),
 ),) 

我如何从数组访问section_id和time_spent数据

php arrays
1个回答
0
投票

请使用下面的代码:另请参见此link

foreach($data as $key => $values){
    foreach ($values as $ikey => $secArr) {
        # code...
        $section_id = $secArr['section_id'];
        $time_spent = $secArr['time_spent'];

        echo 'Section Id: '.$section_id.' | Time Spend:'.$time_spent.'</br>';
    }
}

希望对您有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.