Need to store javascript function in php variable but Notice: Undefined index: on variable [duplicate]

Recently i am making a google map shortcode where my javascript code need to store in a variable.
This is my code where I append my java script code in a php variable but it shows me Undefined index: lng cant find out the

if ( is_array( $GLOBALS['long_lat'] ) ) {
            $markerfunc = '';
                foreach ($GLOBALS['long_lat'] as $item ) {
                    $markerfunc .= 'map.addMarker({
                                lat: '.$item['lat'].',
                                lng: '.$item['lng'].',
                                title: '.$item['title'].',
                                infoWindow: {
                                  content: "<p>'.$item['body'].'</p>"
                                }
                              });';
                }
            }

Read more here: Need to store javascript function in php variable but Notice: Undefined index: on variable [duplicate]

Leave a Reply

Your email address will not be published. Required fields are marked *