What are some best practices for integrating jQuery scripts into PHP projects?

When integrating jQuery scripts into PHP projects, it is important to properly enqueue the jQuery library in your PHP code to ensure it is loaded correctly. This can be done by using the wp_enqueue_script function in WordPress or by manually including the jQuery library in your PHP file. Additionally, it is best practice to localize your jQuery scripts to pass PHP variables to your JavaScript code for better integration between the two languages.

// Enqueue jQuery library in WordPress
function enqueue_jquery() {
    wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'enqueue_jquery');

// Localize PHP variables to jQuery script
function localize_script() {
    wp_localize_script('custom-script', 'php_vars', array(
        'variable1' => $value1,
        'variable2' => $value2
    ));
}
add_action('wp_enqueue_scripts', 'localize_script');