Please I Need Help With This Array - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Please I Need Help With This Array (319 Views)
1 Reply
| Please I Need Help With This Array by cbrass(op): 12:52pm On Oct 04, 2021 |
ArrayThis 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); |
Write An Algorithm To Shuffle An Array • How To Sort Array In Java With User Defined Method ? • How To Allocate Space For Ragged Array Using Calloc() Or Malloc? HELP! • 2 • 3 • 4
How To Create A Hero Image Using HTML And CSS • Why Your Business Needs Inbound Call Centre • A Business Owner’s Guide To Quality Assurance