Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,223 members, 7,953,847 topics. Date: Friday, 20 September 2024 at 07:45 AM |
Nairaland Forum / Science/Technology / Programming / Please I Need Help With This Array (277 Views)
Write An Algorithm To Shuffle An Array / How To Allocate Space For Ragged Array Using Calloc() Or Malloc? HELP! / Java Array Problem (2) (3) (4)
(1) (Reply)
Please I Need Help With This Array by cbrass(m): 12:52pm On Oct 04, 2021 |
Array This is what I want to do: 1 sum all those values and give them to the first key which is [A.txt]. 2. remove the [A.txt] then sum [b.txt] and [C.txt] then give the value to key [B.txt]. 3 Remove [A.txt],[B.txt] then sum whatever is left and give it to [C.txt]. so that my result will look like this Array Language: PHPThanks a lot. |
Re: Please I Need Help With This Array by efelico: 8:29pm On Oct 04, 2021 |
$temp_result=array(); $array=Array("[A.txt]" => 72,"[B.txt]" => 27,"[C.txt]" => 12); $firstKey = array_key_first($array); $sum=array_sum($array); $temp_result=array_merge($temp_result,array($firstKey => $sum)); $output = array_slice($array, 1); $secondKey = array_key_first($output); $sum=array_sum($output); $temp_result=array_merge($temp_result,array($secondKey => $sum)); $output = array_slice($array, 2); $thirdKey = array_key_first($output); $sum=array_sum($output); $temp_result=array_merge($temp_result,array($thirdKey => $sum)); print_r($temp_result); |
(1) (Reply)
Where Can I Lean Artificial Intelligence And Machine Language In Abuja / Looking For Programming Job Or Gigs / Macbook Pro 2017 8gb 256ssd Core I5 Available
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 7 |