1--TEST-- 2Test array_sum() function : usage variations - 'input' array with unexpected values as array element 3--FILE-- 4<?php 5/* 6* Testing array_sum() with array having other than numeric entries 7* strings, bool, null, subarrays & objects 8*/ 9 10echo "*** Testing array_sum() : array with unexpected entries ***\n"; 11 12// empty array 13$input = array(); 14echo "-- empty array --\n"; 15var_dump( array_sum($input) ); 16 17// string array 18$input = array('Apple', 'Banana', 'Carrot', 'Mango', 'Orange'); 19echo "-- array with string values --\n"; 20var_dump( array_sum($input) ); 21 22// bool array 23$input = array( true, true, false, true, false); 24echo "-- array with bool values --\n"; 25var_dump( array_sum($input) ); 26 27// array with null entry 28$input = array(null, NULL); 29echo "-- array with null values --\n"; 30var_dump( array_sum($input) ); 31 32// array with subarray 33$input = array( 34 array(1, 2), 35 array(), 36 array(0) 37); 38echo "-- array with subarrays --\n"; 39var_dump( array_sum($input) ); 40 41class MyClass 42{ 43 public $value; 44 public function __construct($value) 45 { 46 $this->value = $value; 47 } 48} 49// array of objects 50$input = array( 51 new MyClass(2), 52 new MyClass(5), 53 new MyClass(10), 54 new MyClass(0) 55); 56echo "-- array with object values --\n"; 57var_dump( array_sum($input) ); 58 59// Mixed values 60$input = array( 5, -8, 7.2, -1.2, "10", "apple", 'Mango', true, false, null, NULL, array( array(1,2), array(0), array())); 61echo "-- array with mixed values --\n"; 62var_dump( array_sum($input) ); 63echo "Done" 64?> 65--EXPECT-- 66*** Testing array_sum() : array with unexpected entries *** 67-- empty array -- 68int(0) 69-- array with string values -- 70int(0) 71-- array with bool values -- 72int(3) 73-- array with null values -- 74int(0) 75-- array with subarrays -- 76int(0) 77-- array with object values -- 78int(0) 79-- array with mixed values -- 80float(14) 81Done 82