[Solved]PHP array in HTML | Sololearn: Learn to code for FREE!
+ 22

[Solved]PHP array in HTML

Expected output: 42 Actual output: "42"); echo $arr["SoloLearn"]; ?> Please could someone explain how to fix this? In PHP (works fine): <?php $arr = array("SoloLearn"=>"42"); echo $arr["SoloLearn"]; ?> In HTML (doesn't work): <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <?php $arr = array("SoloLearn"=>"42"); echo $arr["SoloLearn"]; ?> </body> </html>

30th Apr 2017, 3:23 PM
Jafca - avatar
5 Answers
+ 8
PHP cannot run in .html files. but html can run in php. Try to put html in PHP compiler not in opposite. hope it helps
5th Apr 2017, 1:24 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 3
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <?php // Try it from inside the Compiler folder (php, IIS, .... etc) $arr = array("SoloLearn"=>"42"); echo $arr["SoloLearn"]; $eld = array("san","man","dan","fan"); echo "<br>". $eld[3]; $san = array("dana"=>"lolo","sana"=>33); echo "<br>". $san["sana"]+=5; echo "<br>". $san["sana"]; ?> </body> </html>
18th May 2017, 3:13 AM
Mohamed Abulnasr
Mohamed Abulnasr - avatar
+ 1
The html code of https://code.sololearn.com/WlA1mrc28Lwg/?ref=app, should be in php file.
5th Apr 2017, 3:22 AM
Calviղ - avatar
+ 1
you can include your html file into your php code by using include statement and vice versa
7th Apr 2017, 1:41 AM
Suhaila Mohammed
Suhaila Mohammed - avatar
right html code ishttps://code.sololearn.com/WlA1mrc28Lwg/?ref=app but html program run
8th Apr 2017, 1:40 PM
Mohd Talib Razzaq
Mohd Talib Razzaq - avatar