Sunday 15 March 2015

mysql - Undefined variable while accessing Associative arrays in PHP -



mysql - Undefined variable while accessing Associative arrays in PHP -

i have 2 arrays, 1 "operid" other "opersums". operid array contains id numbers, , opersums array contains ids attached total looks this:

array 1

{[0] => oper1 [1] => oper2 [2] => 3 [3] => oper4 [4] => oper5 [5] => oper6 [6] => oper7 [7] => oper8 [8] => oper9}

array 2

{["oper3"]=> float(17498.5) ["oper1"]=> float(10383.5) ["oper2"]=> float(6277) ["oper4"]=> float(10224.67) ["oper6"]=> float(3955.65) ["oper5"]=> float(4997.78) ["oper8"]=> float(11382) ["oper9"]=> float(5072.1) ["oper7"]=> float(14759) ["oper-nb3n0hah-1tueubqo"]=> float(1033.45) ["oper-50f6e4ad-9effbec7"]=> float(3058) ["oper-4f05a90b-03b379f9"]=> float(12112.5) ["oper-4db82d0b-796a3081"]=> float(621) ["oper-qxr9ryex-bsmm0g6f"]=> string(4) "0.00" ["oper-qtgjvw8y-1uqtw058"]=> float(10023) ["oper-487b885e-dbbae536"]=> string(6) "340.00" ["oper-shcuaee2-yldfdxsd"]=> float(467) ["oper-416fd551-da6937eb"]=> float(6563) ["oper-50564d75-f1da98ec"]=> string(4) "0.00" ["oper-l65tf5ex-w5qfinca"]=> float(1746) ["oper-52657816-3d6516e2"]=> float(3495) ["oper-4a82c3be-bccc185d"]=> float(0) ["oper-1f2mnwry-nfywuasi"]=> string(6) "255.95"}

i'm wanting gather operator values in both arrays , display totals each operator within each float in array 2, , truncate data. reason want truncate info because displaying info in graph. i'm not great associative arrays, pointers or tips in right direction appreciated. in php way.

here code i'm working far:

$opersums = array(); $operearnedarray[] = array( 'amount' => $row['chargeamount'], 'id' => $row['operatorid']); foreach ($operearnedarray $value) { if($value['id'] == '' || $value['id'] == null) { continue; } if(array_key_exists($value['id'], $opersums)) { $opersums[$value['id']] += $value['amount']; } else { $opersums[$value['id']] = $value['amount']; } } foreach ($opersums $id => $value) { if (in_array($id,$operid)) { echo $id.' => '.$value; } }

but throws these error messages:

notice: undefined variable: opersums warning: invalid argument supplied foreach()

these error messages happen sec foreach loop only

it's $opersums, you're passing $opersums (note case)

php mysql arrays

No comments:

Post a Comment