0

I want result to be

  • label_id 29 and content_text 19 = 1
  • label_id 29 and 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
        )

)

5
  • I hope some one help me. Commented Sep 6, 2018 at 4:15
  • Your question is unclear .Include more information that's why we can help you Commented Sep 6, 2018 at 4:28
  • Do you want to get count of items with label_id 29 ` and content_text` 19? Commented Sep 6, 2018 at 7:35
  • Other users marked your question for low quality and need for improvement. I re-worded/formatted your input to make it easier to read/understand. Please review my changes to ensure they reflect your intentions. Feel free to drop me a comment in case you have further questions or feedback for me. Commented Sep 6, 2018 at 9:13
  • $filter =('product','location','business'); $count = 0; foreach ( $CheckIn as $child ){ if ( $child['content_text'] == $opt['options_id'] && $child['label_id'] == $label['label_id'] && !in_array($label['label_name'], $filter, TRUE)){ $count++; } } Commented Sep 7, 2018 at 10:18

4 Answers 4

1

Please try this code.

$query="select * From user";
$queryResult = $db->query($query);
$result = $queryResult->fetch();
echo $result['count'];
Sign up to request clarification or add additional context in comments.

Comments

0

you can use this function echo count( $arrayResult); but your question is not clear.....

Comments

0

If you want to take a count of unique label_id & context_text field, Then do rekey of the input array with a which-ever field you want then just use count function for taking count.

Am not clear about your question, but I thought might be you want output like this.

1 Comment

$count = 0; foreach ( $CheckIn as $child ){ if ( $child['content_text'] == $opt['options_id'] && $child['label_id'] == $label['label_id'] && !in_array($label['label_name'], $filter, TRUE)){ $count++; } }
0

If you want to count array element which has key/s with a specific value, use the following code.

<?php

// By Moustafa Elkady

function count_by_key_value($arr,$search)
{
    $count = 0;

    foreach ($arr as $array_elements) {
        $matched = 0;
        foreach ($search as $search_key => $search_value) {
            if (isset($array_elements[$search_key]) && $array_elements[$search_key] == $search_value) {
                $matched++;
            }
        }

        if ($matched == count($search)) {
            $count++;
        }

    }

    return $count;
}


$arr = [

    [
        'label_id' => 29,
        'content_text' => 19
    ],

    [
        'label_id' => 29,
        'content_text' => 19
    ],

    [
        'label_id' => 2,
        'content_text' => 19
    ],

];

var_dump(count_by_key_value($arr,['label_id' => 2,'content_text' => 19]));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.