Avatar ·

How to pass variables and data from PHP to JavaScript?

Hello everyone! I'm a beginner PHP developer and I've encountered a problem that seems very simple to me, but I just can't find the right solution.\n\nI have a PHP website, and on one of the pages I get data from a MySQL database. For example, I want to display a list of products with prices and descriptions. I can easily output this in HTML using echo and loops. But now I need to pass this same data to JavaScript, for example, to make interactive product filtering on the client side or to build a price chart.\n\nHere's an example of my PHP code that retrieves the data:\n\n```php\n 'Laptop', 'price' => 50000, 'category' => 'Electronics'],\n ['name' => 'Book', 'price' => 500, 'category' => 'Books'],\n ['name' => 'Phone', 'price' => 25000, 'category'