返回数组中数据的INT值

时间:2013-11-11 04:16:03

标签: php arrays

我的结果是以[0]开头的2个数组,我想要做的是返回“2”的结果 - 因为我有2个“字符串”。我该怎么做?

结果:

Array(1) {
    [0]=> string(32) "b5cfec3e70d0d57ea848d5d8b9f14d61"
}
Array(1) {
    [0]=> string(32) "eda80a3d5b344bc40f3bc04f65b7a357"
}

PHP:

    foreach($cart_contents as $key => $row) {

        if(in_array($key, $skip))

            continue;

             $cartData = $row['rowid'];

             $cartDataArray = explode(" ", $cartData);

             $result = $cartDataArray;

             var_dump($result);
    }

1 个答案:

答案 0 :(得分:1)

如果我做对了,我认为这就是你想要的:

$count = 0;
foreach($cart_contents as $key => $row) {

        if(in_array($key, $skip))
            continue;

        $cartData = $row['rowid'];
        $result = count(explode(" ", $cartData));
        $count += $result;
}
var_dump($count);