Question: I'm completely new to ajax. I want to pass my html form value to php and then get the output from that php page back in the html page

Ajax code 

```
 $("#submit1").click(function(){
 var formData = $("#add-cart-form").serialize();

 $.ajax({
    type: 'POST',
    url: 'test.php',
    dataType : 'json',
    data: {
        'total_load' : $('#total_load').val(),
        'hours' : $('#hours').val(),
    },
     success: function (data) {
       alert(data)
     },
  });
 var result = $.parseJSON(output);
 alert(result[0]);
});

```

Relevant php code

```
$connected_load = $_POST['total_load'];  $no_of_hours = $_POST['hours'];

 echo json_encode(array(
     $connected_load, 
     $selected_inverter["model"], 
     $selected_inverter["voltage"], 
     $selected_inverter["type"],
     $no_of_hours,$selected_battery));

```

Answer: 
You can use `std::max_element` with a lambda express to search a range for the maximum element using your specific comparison criteria. In this case you define your comparison function to compare only the `int` value in the pair:

```
std::vector<std::pair<int, std::string>> myList = { ... };

auto find = std::max_element(begin(myList), end(myList),
    [](const std::pair<int, std::string>& pairA, const std::pair<int, std::string>& pairB)
    {
        return pairA.first < pairB.first;
    }
);

std::string maximumString = find->second;

```
If you can sort it, then you can get either the first element, if you sorted it descenent, or the last element, if you sorted it ascendent.

But if you don't want to sort it, you can go throughout the vector, and at every step checking for the highest int, and memorize the string:

```
maxInt = array[0]; //int
maxString = array[0].String;
for (i=1;i<arrayLength;i++){
      if (array[i] > maxInt) {
             maxInt = array[i];
             maxString = array[i].String;
      } 
}

```

And then you can simply print out the maxString.