1

I have an auto generated array liek so.. (looks like real data but has been anonymized)..

Array
(
    [16280] => Array
        (
            [0] => 16280
            [1] => 19-04696-34480
            [2] => Helen*smith
            [3] => helen smith
            [4] => [email protected]
            [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] => 
        )
)

And I am trying to do a simple addition sum but both..

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

and

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

Result in "0" when in this example it should be adding up to 1.49 what am I doing wrong, please? Is it something to do with having to convert them (integer or a string.)? and if so how do I go about this?

1 Answer 1

2

You can convert the strings to floats with this:

<?php echo floatval(substr($order[25], 1, 4)) + floatval(substr($order[77], 1, 4)); ?>
Sign up to request clarification or add additional context in comments.

7 Comments

kpie thanks, can you explain what the "1, 4" parts do please?
that's the start and end index for the sub string, it means you take the first through the 4th character in the string.
thanks for explaining, unfortunately though it is still resulting in "0" with a straight copy/paste of your example code, any ideas why? Could it be because the values start with "£"
Yeah my bad £ is actually 2 characters so its floatval(substr($order[25], 2))) (becasue you don't actually need to include an ending index...)
Perfect thanks, i had worked it out since typing the comment but had used "2, 5" will change now you have said we don;t actually need to include an ending index. thanks again for your help.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.