Answers for "PHP multidimensional array WITH STRING AND NUMBER TO FIND TOTAL"

PHP
2

array_sum in multidimensional array php

<?php
$items = [
    ['label' => 'cake', 'name' => 'Cake', 'price' => 150],
    ['label' => 'pizza', 'name' => 'Pizza', 'price' => 250],
    ['label' => 'puff', 'name' => 'Veg Puff', 'price' => 20],
    ['label' => 'samosa', 'name' => 'Samosa', 'price' => 14]
];

$arrSum = array_sum(array_column($items, 'price', 'name'));
print "Sum of Array : ".$arrSum."<br/>";
?>
Posted by: Guest on February-04-2021
0

get the matched value from 2 multidimensional array in php by id

<?php
  $a = Array(
      Array('id' => 1, 'affiliate_id' => 190),
      Array('id' => 2, 'affiliate_id' => 946)
  );

  $b = Array(
      Array('id' => 1, 'user_id' => 190),
      Array('id' => 2, 'user_id' => 246),
      Array('id' => 3, 'user_id' => 249),
      Array('id' => 3, 'user_id' => 250)
  );

  $c = array_map(function ($arr) { return $arr['affiliate_id']; }, $a);
  $d = array_map(function ($arr) { return $arr['user_id']; }, $b);

  $e = array_intersect($c, $d);

  // Output
  // Array ( [0] => 190 )

?>
Posted by: Guest on August-18-2021

Code answers related to "PHP multidimensional array WITH STRING AND NUMBER TO FIND TOTAL"

Browse Popular Code Answers by Language