F
F
Farik Azizov2020-05-19 03:59:53
PHP
Farik Azizov, 2020-05-19 03:59:53

How to use PHP Foreach Loop in Javascript?

Welcome all!

There is a calculator for calculating the fare using the YandexMaps API.
The cost of some routes (for example: Simferopol - Koktebel) will be calculated according to the previously set tariff. On JS somehow implemented this mechanism.

Here is a piece of code:

if ((jQuery("#from").val().indexOf("Симферополь") !== -1) && (jQuery("#to").val().indexOf("Коктебель") !== -1)) {
  var curPrice = 2000;
  console.log("Маршрут: Симферополь - Коктебель");
} else if ((jQuery("#to").val().indexOf("Симферополь") !== -1) && (jQuery("#from").val().indexOf("Коктебель") !== -1)) {
  var curPrice = 2000;
  console.log("Маршрут: Коктебель - Симферополь");
} else {
  var curPrice = +(jQuery("#price" + jQuery("#class").val()).val()) * Math.floor(length);
}


Now I want to make sure that these routes are added using custom fields on the WordPress CMS using PHP Foreach.

I will be grateful for any help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2020-05-19
@bizpartneer

Firstly, php will not work in js, js has its own cycles
. Secondly, it's not very clear what you don't want. Pass list of routes from custom fields to js ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question