Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将foreach循环与数组一起使用_Php_Arrays_Foreach - Fatal编程技术网

Php 将foreach循环与数组一起使用

Php 将foreach循环与数组一起使用,php,arrays,foreach,Php,Arrays,Foreach,我有一个数组,由$details\u sort表示 我想在foreach循环中使用我的数组 like foreach (`$details_sort` as $detail) { } Array ( [0] => Array ( [id] => 1 [score] => 233 [user_id] => 4 [date] => 2014-0

我有一个数组,由
$details\u sort
表示

我想在foreach循环中使用我的数组

like foreach (`$details_sort` as $detail)
{


} 

Array
(
    [0] => Array
        (
            [id] => 1
            [score] => 233
            [user_id] => 4
            [date] => 2014-02-03 00:00:00

        )

    [1] => Array
        (
            [id] => 2
            [score] => 1256
            [user_id] => 5
            [date] => 2014-02-05 00:00:00

        )

    [2] => Array
        (
            [id] => 4
            [score] => 123
            [user_id] => 7
            [date] => 2014-03-04 00:00:00

        )

    [3] => Array
        (
            [id] => 3
            [score] => 100

        )

    [4] => Array
        (
            [id] => 5
            [score] => 8
            [user_id] => 2
            [date] => 2014-03-13 00:00:00

        )

)


这是php的基础。你应该努力一下。


“我想在foreach循环中创建我的数组。”我甚至不知道你在问什么。我在哪里漏掉了引号?请指定:)
echo$detail['userid]应该是
echo$detail['userid']啊,你有一双调试的眼睛,@AwladLiton的斑点很好
foreach($details_sort as $detail) {
    foreach($detail as $attribute => $value) {
        echo "$attribute => $value";
    }
}
foreach($details_sort as $detail) {
    echo $detail['id'];
    echo $detail['score'];
    echo $detail['userid'];
    echo $detail['date'];
}
 foreach ($details_sort as $detail)
    {
    echo $detail['id'];
    echo $detail['score'];
    echo $detail['user_id'];
    echo $detail['date'];

    }