Write a PHP program that multiplies corresponding elements of two given lists


Introduction

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following excercise..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. <?php
  2. function multiply_two_lists($x, $y)
  3. {
  4. $a = explode(' ',trim($x));
  5. $b = explode(' ',trim($y));
  6. foreach($a as $key=>$value){
  7. $output[$key] = $a[$key]*$b[$key];
  8. }
  9. return implode(' ',$output);
  10. }
  11. echo multiply_two_lists(("20 12 5"), ("1 3 3"))."\n";
  12. ?>

Result

python language techstudy.org

     





Related Topics




Popular Posts