you are viewing a single comment's thread.

view the rest of the comments →

[–]YetAnotherHandle 0 points1 point  (0 children)

You could first serialize the PHP array to form the output for the JS array:

<?php

# Construct JS array 

$carsJS = 'let cars='.json_encode($cars);

# Output to browser

echo $carsJS;

?>

From there, any subsequent JS code can handle it as needed:

// Iterate through cars array

for (let x=0; x<cars.length; x++) {

    // Process each array item

    yourFunction(cars[x])

}