Answers for "array column sum php"

PHP
5

php sum array elements

<?php
$a=array(5,15,25);
echo array_sum($a);
?>
Posted by: Guest on August-06-2020
3

array_column in php

$a = array(
  array(
    'id' => 5698,
    'first_name' => 'Peter',
    'last_name' => 'Griffin',
  ),
  array(
    'id' => 4767,
    'first_name' => 'Ben',
    'last_name' => 'Smith',
  ),
  array(
    'id' => 3809,
    'first_name' => 'Joe',
    'last_name' => 'Doe',
  )
);

$last_names = array_column($a, 'last_name');
print_r($last_names);
Posted by: Guest on November-25-2020

Browse Popular Code Answers by Language