如何使用PHP从此数组中得出“计数”?

时间:2018-09-06 04:11:00

标签: php arrays get

我希望结果成为

  • label_id 29和content_text 19 = 1
  • label_id 29和content_text 27 = 1
Array
(
    [0] => Array
        (
            [row_id] => 70
            [content_id] => 354
            [label_id] => 28
            [type_id] => 6
            [label_name] => product
            [content_text] => 14
        )

    [1] => Array
        (
            [row_id] => 70
            [content_id] => 355
            [label_id] => 29
            [type_id] => 6
            [label_name] => location
            [content_text] => 26
        )

    [2] => Array
        (
            [row_id] => 70
            [content_id] => 356
            [label_id] => 30
            [type_id] => 6
            [label_name] => business
            [content_text] => 35
        )

    [3] => Array
        (
            [row_id] => 70
            [content_id] => 362
            [label_id] => 35
            [type_id] => 6
            [label_name] => visibility
            [content_text] => 41
        )

    [4] => Array
        (
            [row_id] => 71
            [content_id] => 365
            [label_id] => 28
            [type_id] => 6
            [label_name] => product
            [content_text] => 14
        )

    [5] => Array
        (
            [row_id] => 71
            [content_id] => 366
            [label_id] => 29
            [type_id] => 6
            [label_name] => location
            [content_text] => 27
        )

    [6] => Array
        (
            [row_id] => 71
            [content_id] => 367
            [label_id] => 30
            [type_id] => 6
            [label_name] => business
            [content_text] => 35
        )

    [7] => Array
        (
            [row_id] => 71
            [content_id] => 373
            [label_id] => 35
            [type_id] => 6
            [label_name] => visibility
            [content_text] => 42
        )

    [8] => Array
        (
            [row_id] => 74
            [content_id] => 389
            [label_id] => 28
            [type_id] => 6
            [label_name] => product
            [content_text] => 14
        )

    [9] => Array
        (
            [row_id] => 74
            [content_id] => 390
            [label_id] => 29
            [type_id] => 6
            [label_name] => location
            [content_text] => 21
        )

    [10] => Array
        (
            [row_id] => 74
            [content_id] => 391
            [label_id] => 30
            [type_id] => 6
            [label_name] => business
            [content_text] => 35
        )

    [11] => Array
        (
            [row_id] => 74
            [content_id] => 397
            [label_id] => 35
            [type_id] => 6
            [label_name] => visibility
            [content_text] => 42
        )

    [12] => Array
        (
            [row_id] => 85
            [content_id] => 420
            [label_id] => 28
            [type_id] => 6
            [label_name] => product
            [content_text] => 14
        )

    [13] => Array
        (
            [row_id] => 85
            [content_id] => 421
            [label_id] => 29
            [type_id] => 6
            [label_name] => location
            [content_text] => 18
        )

    [14] => Array
        (
            [row_id] => 85
            [content_id] => 422
            [label_id] => 30
            [type_id] => 6
            [label_name] => business
            [content_text] => 35
        )

    [15] => Array
        (
            [row_id] => 85
            [content_id] => 428
            [label_id] => 35
            [type_id] => 6
            [label_name] => visibility
            [content_text] => 42
        )

    [16] => Array
        (
            [row_id] => 136
            [content_id] => 531
            [label_id] => 28
            [type_id] => 6
            [label_name] => product
            [content_text] => 14
        )

    [17] => Array
        (
            [row_id] => 136
            [content_id] => 532
            [label_id] => 29
            [type_id] => 6
            [label_name] => location
            [content_text] => 27
        )

    [18] => Array
        (
            [row_id] => 136
            [content_id] => 533
            [label_id] => 30
            [type_id] => 6
            [label_name] => business
            [content_text] => 35
        )

    [19] => Array
        (
            [row_id] => 136
            [content_id] => 539
            [label_id] => 35
            [type_id] => 6
            [label_name] => visibility
            [content_text] => 42
        )

    [20] => Array
        (
            [row_id] => 56
            [content_id] => 258
            [label_id] => 28
            [type_id] => 6
            [label_name] => product
            [content_text] => 14
        )

    [21] => Array
        (
            [row_id] => 56
            [content_id] => 259
            [label_id] => 29
            [type_id] => 6
            [label_name] => location
            [content_text] => 24
        )

    [22] => Array
        (
            [row_id] => 56
            [content_id] => 261
            [label_id] => 30
            [type_id] => 6
            [label_name] => business
            [content_text] => 35
        )

    [23] => Array
        (
            [row_id] => 56
            [content_id] => 267
            [label_id] => 35
            [type_id] => 6
            [label_name] => visibility
            [content_text] => 41
        )

)

4 个答案:

答案 0 :(得分:1)

请尝试使用此代码。

$query="select * From user";
$queryResult = $db->query($query);
$result = $queryResult->fetch();
echo $result['count'];

答案 1 :(得分:0)

您可以使用此功能echo count( $arrayResult); 但是您的问题不清楚。.....

答案 2 :(得分:0)

如果要对唯一的label_id和context_text字段进行计数,则使用想要的任何字段对输入数组进行键更新,然后仅使用count函数进行计数。

不清楚您的问题,但我想可能是您想要这样的输出。

答案 3 :(得分:0)

如果要计算具有特定值的键的数组元素,请使用以下代码。

<com.example.rinor.chronometertimer.Chronometer
    android:layout_width="match_parent"
    android:layout_height="wrap_content">...
</com.example.rinor.chronometertimer.Chronometer>