2017-01-11 17 views
0
Array 
(
    [1] => Array 
     (
      [0] => Array 
       (
        [partyplan_select_products] => 1 
        [product_name] => Books 
        [partyplan_amazonurl_product] => http://www.flipkart.com 
        [partyplan_product_image_id] => 18320 
        [partyplan_product_image] => http://local.enjoius/wp-content/uploads/2016/11/acktobwufyhopfql.jpg 
        [partyplan_min_product_price] => 25.00 
        [partyplan_max_product_price] => 30.00 
        [partyplan_product_qty] => 0 
       ) 

      [1] => Array 
       (
        [partyplan_select_products] => 1 
        [product_name] => Wallpaers 
        [partyplan_amazonurl_product] => http://www.Amazon.com 
        [partyplan_product_image_id] => 18351 
        [partyplan_product_image] => http://local.enjoius/wp-content/uploads/2016/11/20161114015751-3D-Nature-Wallpapers-HD-2.jpg 
        [partyplan_min_product_price] => 10.00 
        [partyplan_max_product_price] => 50.00 
        [partyplan_product_qty] => 100 
       ) 

      [2] => Array 
       (
        [partyplan_select_products] => 1 
        [product_name] => Disco Lights 
        [partyplan_amazonurl_product] => http://www.google.com 
        [partyplan_product_image_id] => 18328 
        [partyplan_product_image] => http://local.enjoius/wp-content/uploads/2016/11/relwwzfpaupcvhlc.jpg 
        [partyplan_min_product_price] => 85.00 
        [partyplan_max_product_price] => 100.00 
        [partyplan_product_qty] => 75 
       ) 

      [5] => Array 
       (
        [partyplan_select_products] => 1 
        [product_name] => Table 
        [partyplan_amazonurl_product] => http://www.google.com 
        [partyplan_product_image_id] => 18416 
        [partyplan_product_image] => http://local.enjoius/wp-content/uploads/2016/11/blog_img.jpg 
        [partyplan_min_product_price] => 150.00 
        [partyplan_max_product_price] => 500.00 
        [partyplan_product_qty] => 15 
       ) 

     ) 

    [2] => Array 
     (
      [3] => Array 
       (
        [partyplan_select_products] => 2 
        [product_name] => Waiters 
        [partyplan_amazonurl_product] => http://www.google.com 
        [partyplan_product_image_id] => 18373 
        [partyplan_product_image] => http://local.enjoius/wp-content/uploads/2016/11/20161123011316-8454547519_f8116520e1_b.jpg 
        [partyplan_min_product_price] => 150.00 
        [partyplan_max_product_price] => 500.00 
        [partyplan_product_qty] => 25 
       ) 

      [4] => Array 
       (
        [partyplan_select_products] => 2 
        [product_name] => sadasdfs 
        [partyplan_amazonurl_product] => http://www.google.com 
        [partyplan_product_image_id] => 18362 
        [partyplan_product_image] => http://local.enjoius/wp-content/uploads/2016/11/20161116041623-8215602321_69d9939b8b_b.jpg 
        [partyplan_min_product_price] => 150.00 
        [partyplan_max_product_price] => 500.00 
        [partyplan_product_qty] => 25 
       ) 
     ) 
) 

要素の増分に従って、[partyplan_select_products]の数を取得する必要があります。多次元配列elmentsを数える

+0

partyplan_select_productsキーを持つ配列のすべての値の合計を意味しますか? – rahulsm

+0

yaしかし、あなたはidが 'partyplan_select_products'で異なっているのを見ることができます – sukhjeet

+0

私はそのIDのためにカウントを取得します@VforVendetta – sukhjeet

答えて

0

これは、再帰的な配列の列関数である

function array_column_recursive(array $haystack, $needle) { 
    $found = []; 
    array_walk_recursive($haystack, function($value, $key) use (&$found, $needle) { 
     if ($key == $needle) 
      $found[] = $value; 
    }); 
    return $found; 
} 

、これを試してみてください。あなたの配列に表示されているようなランダムなキーは考慮されません。その後 、

あなたが得る、

$sum_arr = array_column_recursive($your_arr, 'partyplan_select_products'); 

そして最後に合計数を取得するには、 あなたはarray_sum機能を使用することができます。

$count = array_sum($sum_arr); 

これがあなたに役立つことを願っています。

+0

@v vendettaのために私にこれを試してみましょう – sukhjeet

+0

あなたの時間をかけて、その仕事がわかったら – rahulsm

+0

私は総数Vをvendettarのために受け取っています – sukhjeet