How to add dynamic generated jQuery code in my theme which is accepted by themeforest ?

Hi, I am working on a theme and want to add some JQuery code which contains dynamic data based on php selection. Code looks some thing like show below:

jQuery(document).ready(function(){ if (jQuery('#gallery-listed<?php echo $count;?>').length) { var $container = jQuery('#gallery-listed<?php echo $count;?>'); $container.imagesLoaded( function(){ $container.isotope({ filter: '*', animationOptions: { duration: 750, easing: 'linear', queue: false } }); }); jQuery('#filterlist_v5<?php echo $count;?> a').click(function() { jQuery('#filterlist_v5<?php echo $count;?> .current').removeClass('current'); jQuery(this).addClass('current');
				var selector = jQuery(this).attr('data-filter');
					filter: selector,
					animationOptions: {
						duration: 750,
						easing: 'linear',
						queue: false
				return false;

This code is inside one of my php file and I can’t use it in my custom-scripts.js file because I have to use that php page data in this script.

That counter simply increments my div id each time new instance of my code created. If user want to have multiple same things then this will work without any issue or conflict. But, the problem is now I want to know the exact themeforest method so that it can be inserted in the footer and code accepted.

let me know what i want is possible or any other best approcah or any thing to solve my issue plz.