multidimensional array - Has anyone ever seen this happen in a php freach loop? -


i built multi-dimensional array query has 101 keys

when echo $result['q101'] before foreach loop shows proper data..

after loop array modified somehow $result['q101'] => 8...???

note: happens last key regardless of number.

> [q99] => array >     ( >         [name] => disentanglement love relationship >         [abbr] => dflr >         [type] => ascending >         [response] => >         [score] => 3 >     ) >  > [q100] => array >     ( >         [name] => feelings of self worth >         [abbr] => fosw >         [type] => ascending >         [response] => >         [score] => 1 >     ) >  > [q101] => 8 /// wtf this..?? 

below culprit.. if remove hunky dory.

foreach ($result $key => $val){     $response_table .= '<tr><td>'.str_replace('q', '', $key).'</td><td>'.$val['response'].'</td><td>'.$val['abbr'].'</td><td>'.$val['type'].'</td><td>'.$val['score'].'</td></tr>';     $min[$val['abbr']] += 1;     $max[$val['abbr']] += 1;     } 

make sure unsetting $key, $val after foreach. http://php.net/manual/en/control-structures.foreach.php reference of $value , last array element remain after foreach loop. recommended destroy unset().


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -