如何在codeigniter中获得0索引值?

时间:2017-09-18 12:24:41

标签: codeigniter

Array ( [0] => 18 [1] => 1 )

我怎么才能获得0指数值?我在codeigniter中使用此代码。任何人都可以帮忙吗?这可能是每个循环所以它访问所有索引,但只显示零索引?

    foreach($m as $m)
{
    echo $m->['0'];
}

3 个答案:

答案 0 :(得分:0)

如果你只想要第一个索引,那么你不需要foreach循环 只需写下:

echo $m[0];

如果你想要所有数组索引,那么:

foreach ($m as $key => $value) {
  echo $key;
}

答案 1 :(得分:0)

试试这个:

print_r($m[0]); 

foreach($m as $m)
{
    echo $m['0'];
}

答案 2 :(得分:0)

以下是获取索引0值的代码 // $声明包含多个值的数组变量

$array=array('0' =>"first value",'1' =>"second value",'2' =>"third value" );
        echo "<pre>";
        print_r($array); // helps in printing the value key and value
        //iterating through each values in the array
        foreach ($array as $key => $value) {
            if($key==0) //checks if key is 0
            {
                echo $value; //prints the value in key 0
            }
        }