.. _key-element-cannot-be-a-reference: Key element cannot be a reference --------------------------------- .. meta:: :description: Key element cannot be a reference: In a foreach() loop, the value may be a reference, when it needs to be updated. :og:image: https://php-errors.readthedocs.io/en/latest/_static/logo.png :og:type: article :og:title: Key element cannot be a reference :og:description: In a foreach() loop, the value may be a reference, when it needs to be updated :og:url: https://php-errors.readthedocs.io/en/latest/messages/key-element-cannot-be-a-reference.html :og:locale: en :twitter:card: summary_large_image :twitter:site: @exakat :twitter:title: Key element cannot be a reference :twitter:description: Key element cannot be a reference: In a foreach() loop, the value may be a reference, when it needs to be updated :twitter:creator: @exakat :twitter:image:src: https://php-errors.readthedocs.io/en/latest/_static/logo.png .. raw:: html Description ___________ In a foreach() loop, the value may be a reference, when it needs to be updated. The key, on the other hand, cannot be changed, and hence, cannot have a reference. Example _______ .. code-block:: php $value) {} ?> Solutions _________ + Remove the reference from the key. + Use array_flip() to make the keys the values, and update them, then use the same function again.