0

I will try to be as brief as possible.

I have a php file with one function. I want that function to return a array which will contain multiple variables. Next I want to load this array in my html file.

The structure of my php:

 <?php
 function solve(){
 if($oblast == "1"){

// 

    switch ($sadzba) {
        case "1": $price1=.... ; break;
        case "2": $price2=.....;break;
 ...

                     }
 }

 $result = array($price1, $price2);
 return $result;
 }solve();

And now I want to access to $result in my html file so I can do this for example:

 <div id="first"><?php echo $result[0] ?></div>
 <div id="second"><?php echo $result[1] ?></div>

How can be this done please?

3
  • When you say "load this array in my html file", are you referring to the same html/php file where you generated the array? Commented Jan 18, 2014 at 1:52
  • No, php and html are 2 separate files Commented Jan 18, 2014 at 1:53
  • I believe your html should be saved as a php file? Commented Jan 18, 2014 at 2:03

1 Answer 1

1

in your file do the following:

Please understand something VERY IMPORTANT: variables in php are not global by default . . so your code will never run until you pass $oblast as paramater to the funciton solve or add global $oblast to it (But the 2nd is highly not recommended)

 <?php
 function solve($oblast){
     if($oblast == "1"){
         switch ($sadzba) {
             case "1": $price1=.... ; break;
             case "2": $price2=.....;break;
         }     
     }   
     $result = array($price1, $price2);
     return $result;
}
$result = solve($oblast); // <-- make sure this variable is set e.g. $oblast = $_POST['something'];
include "path/to/html_file.html";
Sign up to request clarification or add additional context in comments.

3 Comments

and what about my html file? Do I have to include something, or load something with jquery?
Check the rest of the answer above, please market it correct if it works.
Unfortunately it is not working. I push the submit button, I pass form values to that php file, but the result is not showing. Do you have any other idea?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.