简单 php 数组总和不起作用(加起来为零)

Simple php array sum not working (add's up to zero)

我有一个自动生成的数组 liek 所以..(看起来像真实数据但已匿名)..

Array
(
    [16280] => Array
        (
            [0] => 16280
            [1] => 19-04696-34480
            [2] => Helen*smith
            [3] => helen smith
            [4] => hellieh77@live.com
            [5] => 
            [6] => 1 green hill
            [7] => Sedgley
            [8] => Dudley
            [9] => West Midlands
            [10] => DY4 2BJ
            [11] => United Kingdom
            [12] => Helen smith
            [13] => +44 7780 123456
            [14] => 1 green hill
            [15] => Sedgley
            [16] => Dudley
            [17] => West Midlands
            [18] => DY4 2BJ
            [19] => United Kingdom
            [20] => 
            [21] => 
            [22] => 
            [23] => 
            [24] => 4
            [25] => £1.99
            [26] => £0.00
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £1.99
            [31] => No
            [32] => PayPal
            [33] => 20-Mar-20
            [34] => 20-Mar-20
            [35] => 
            [36] => 
            [37] => 
            [38] => 
            [39] => 
            [40] => 
            [41] => 
            [42] => 97A17674UX562625N
            [43] => Royal Mail 1st Class
            [44] => 
            [45] => 
            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
            [52] => 16280
            [53] => 19-04696-34480
            [54] => Helen*smith
            [55] => 
            [56] => 
            [57] => 
            [58] => 
            [59] => 
            [60] => 
            [61] => 
            [62] => 
            [63] => 
            [64] => 
            [65] => 
            [66] => 
            [67] => 
            [68] => 
            [69] => 
            [70] => 
            [71] => 
            [72] => 302804824258
            [73] => SAVE A BIKER OPEN YOUR EYES - THINK BIKE DECAL STICKER WALL CAR VAN LAPTOP BIKE 
            [74] => Default Colour (if non specified) = WHITE
            [75] => No
            [76] => 1
            [77] => £0.50
            [78] => 
            [79] => 
            [80] => 
            [81] => 
            [82] => 
            [83] => 
            [84] => 
            [85] => 20-Mar-20
            [86] => 
            [87] => 23-Mar-20
            [88] => 
            [89] => 
            [90] => 
            [91] => No
            [92] => 
            [93] => 
            [94] => 
            [95] => 
            [96] => 
            [97] => 1726051559020
            [98] => 
            [99] => 
            [100] => 
            [101] => 
            [102] => 
            [103] => 
            [104] => 16280
            [105] => 19-04696-34480
            [106] => Helen*smith
            [107] => 
            [108] => 
            [109] => 
            [110] => 
            [111] => 
            [112] => 
            [113] => 
            [114] => 
            [115] => 
            [116] => 
            [117] => 
            [118] => 
            [119] => 
            [120] => 
            [121] => 
            [122] => 
            [123] => 
            [124] => 303176299926
            [125] => Personalised Mrs Hinch /Zoflora/Lenor 2x Vinyl Stickers Storage Baskets Bottles[Glossy Yellow,25mm (2.5cm)]
            [126] => CLNLBL_Gl_50
            [127] => No
            [128] => 1
            [129] => £0.46
            [130] => 
            [131] => 
            [132] => 
            [133] => 
            [134] => 
            [135] => 
            [136] => 
            [137] => 20-Mar-20
            [138] => 
            [139] => 23-Mar-20
            [140] => 
            [141] => 
            [142] => 
            [143] => No
            [144] => 
            [145] => 
            [146] => 
            [147] => 
            [148] => 
            [149] => 1726051564020
            [150] => [Colour:Glossy Yellow,Size (Height):25mm (2.5cm)]
            [151] => 
            [152] => 
            [153] => 
            [154] => 
            [155] => 
            [156] => 16280
            [157] => 19-04696-34480
            [158] => Helen*smith
            [159] => 
            [160] => 
            [161] => 
            [162] => 
            [163] => 
            [164] => 
            [165] => 
            [166] => 
            [167] => 
            [168] => 
            [169] => 
            [170] => 
            [171] => 
            [172] => 
            [173] => 
            [174] => 
            [175] => 
            [176] => 303261272249
            [177] => Heart Spiral Optical Illusion - Love - Vinyl Decal Sticker - 16 Colour Choices[Red,Standard,STD 95x95mm]
            [178] => heartspiral _Re_ST_St
            [179] => No
            [180] => 1
            [181] => £0.45
            [182] => 
            [183] => 
            [184] => 
            [185] => 
            [186] => 
            [187] => 
            [188] => 
            [189] => 20-Mar-20
            [190] => 
            [191] => 23-Mar-20
            [192] => 
            [193] => 
            [194] => 
            [195] => No
            [196] => 
            [197] => 
            [198] => 
            [199] => 
            [200] => 
            [201] => 1726051560020
            [202] => [Colour:Red,Fitment:Standard,Size:STD 95x95mm]
            [203] => 
            [204] => 
            [205] => 
            [206] => 
            [207] => 
            [208] => 16280
            [209] => 19-04696-34480
            [210] => Helen*smith
            [211] => 
            [212] => 
            [213] => 
            [214] => 
            [215] => 
            [216] => 
            [217] => 
            [218] => 
            [219] => 
            [220] => 
            [221] => 
            [222] => 
            [223] => 
            [224] => 
            [225] => 
            [226] => 
            [227] => 
            [228] => 303383128781
            [229] => Not all disabilities are visible (CIRCLE Design) Vinyl Sticker for Car/Van/Wall[Reverse Cut,STD 95x95mm,White]
            [230] => Notalldisabilitiescircle_Li_XL_St
            [231] => No
            [232] => 1
            [233] => £0.58
            [234] => 
            [235] => 
            [236] => 
            [237] => 
            [238] => 
            [239] => 
            [240] => 
            [241] => 20-Mar-20
            [242] => 
            [243] => 23-Mar-20
            [244] => 
            [245] => 
            [246] => 
            [247] => No
            [248] => 
            [249] => 
            [250] => 
            [251] => 
            [252] => 
            [253] => 1726051562020
            [254] => [Fitment:Reverse Cut,Sticker Size:STD 95x95mm,Sticker Colour:White]
            [255] => 
            [256] => 
            [257] => 
            [258] => 
            [259] => 
        )
)

我正在尝试做一个简单的加法求和,但是两者..

<?php echo $order[25] + $order[77]; ?>

<?php
$sum1 = array($order[25], $order[77]);
echo array_sum($sum1);
?>

结果为“0”,而在此示例中它应该加起来为 1.49,请问我做错了什么? 这与必须转换它们(整数或字符串)有关吗?如果可以,我该怎么做?

您可以使用以下方法将字符串转换为浮点数:

<?php echo floatval(substr($order[25], 1, 4)) + floatval(substr($order[77], 1, 4)); ?>