Question

1. Print out information of PHP use phpinfo() function. 2. Write a program that check and...

1. Print out information of PHP use phpinfo() function.
2. Write a program that check and print odd / even numbers (from number 1 to 100 using for/while loop). Display the results within an HTML table with 2 columns as shown below:
NUMBERS
RESULTS
1
ODD
2
EVEN
3
ODD
HINT: use <table> tags to create a table, <th> tags for ‘Numbers’ and ‘Results’. Wrap code PHP inside HTML code. For example:
​<html>
​​<title>CHECK ODD or EVEN</title>
​​<body>
​​​<table>
​​​​<?php
​​​​​echo “<tr><td>1</td><td>Odd</td></tr>”;
​​​​?>
​​​</table>
​​</body>
​</html>
3. Do the following steps in one .php file and try to manage the output to be clear to see:
a. Create a dimensional associative array that has at least 8 key/element pairs and var_dump() the array.
b. Print out the array in a table with keys and values (like you do in question 1).
c. Use assort() function to sort the array in ascending order based on the value and var_dump() the new array.
d. Use unset() function to remove an element by key from the array then print the modified array by use var_dump() function. HINT: unset($my_array[‘key’]).
4. Create a two-dimensional array that contains the following information about twitter users:(HINT: the second dimension should be associative, with keys username, tweets, followers, following.) These refer to the number of tweets the user tweeted, how many followers the user has and how many other users this user is following! (The first dimension can be indexed, and you can add Username to the second dimension, or you can have both dimensions be associative, where the Username points to the first person etc. In this case the key joeDoe, for example, has the value array(tweets=>20000,followers=>45,following=>8)
User name
Tweets
Number of Followers
Following
joeDoe
20000
45
8
JohnD
62000
123
160
computerSavy
75
1
25
myTwitterAccount
1800
15
6
a. Print out the array in HTML format using table tags.
b. Sort the array by tweets and print out in table format
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Rate my solution and please do comment if any doubt

I have clearly stated every code and its output

Don't forget to host the file before opening in the browser

1 Code:

<!DOCTYPE html>
<html>
<head>
   <title>PHP info</title>
</head>
<body>
<?php
   phpinfo();  
?>
</body>
</html>

1 Output:

PHP Version 7.3.8 php System Build Date Compiler Architecture Configure Command Server API Virtual Directory Support Configur

2 Code:


<!DOCTYPE html>
<html>
<head>
   <title>CHECK ODD or EVEN</title>
</head>
<body>
   <table border="1">
       <tr>
           <th>NUMBER</th>
           <th>RESULT</th>
       </tr>
       <?php
           //below loop will traverse from 1 to 100
           for($i=1;$i<=100;$i++)
           {
               //If is is divisble by 2 then it is even
               if($i%2==0)
                   echo "<tr>
                           <td>$i</td>
                           <td>EVEN</td>
                       </tr>";
               //If is is not divisble by 2 then it is odd
               else
                   echo"<tr>
                           <td>$i</td>
                           <td>ODD</td>
                       </tr>";
               //here i am printing the row and cells $i and its type(odd or even)
           }
       ?>
   </table>
</body>
</html>

2 Output:

NUMBER RESULT ODD EVEN ODD EVEN ODD EVEN ODD EVEN ODD EVEN ODD EVEN ODD 14 EVEN 15 ODD 16 EVEN ODD EVEN ODD EVEN ODD EVEN ODD

3 Code:

<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>
<?php
   //$arr is the array declaration with its keys and values
   $arr=array("A"=>4,"B"=>3,"C"=>1,"D"=>2,"E"=>8,"F"=>7,"G"=>6,"H"=>5);
   //var_dump() will define the data type of the keys and values
   var_dump($arr);
   //Table starts here
   echo "<table border='1'>";
   //below is the table heading
   echo "<tr><th>KEY</th><th>VALUE</th></tr>";
   //each key and value is take from $arr and added to the table
   foreach($arr as $x => $x_value)
   {
   echo "<tr><td>$x</td><td>$x_value</td></tr>";
   }
   echo "</table>";
   //The array is sorted based on values
   asort($arr);
   var_dump($arr);
   //var_dump() will define the data type of the keys and values
   echo "<br>";
   //unsetting the value of "B" below will remove "B" from the arry
   unset($arr["B"]);
   var_dump($arr);
   //var_dump() will define the data type of the keys and values
?>

</body>
</html>

3 Output:

array(8) { [A]=> int(4) [B]=> int(3) [C]=> int(1) [D]=> int(2) [E]=> int(8) [F]=> int(7) [G]=> int(0) [H]=> i

4 Code:

<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>
   <?php
       $arr=array("joeDoe"=>array("tweets"=>20000,"followers"=>45,"following"=>8),
               "JohnD"=>array("tweets"=>62000,"followers"=>123,"following"=>160),
               "computerSavy"=>array("tweets"=>75,"followers"=>1,"following"=>25),
               "myTwitterAccount"=>array("tweets"=>1800,"followers"=>15,"following"=>6)
               );
       //it is the array of users
       //table tag starts here
       echo "<table border='1'>";
       echo "<tr><th>User name</th>
               <th>Tweets</th>
               <th>No. of followers</th>
               <th>Following</th>
               </tr>";
       //table headings are given above
       //below loop will take each element from $arr
       //Key and its value is taken form arr
       foreach ($arr as $key => $value) {
           echo "<tr>
               <td>$key</td>";
               //as the value comtains other info about user
               //we have to traverse through it
               foreach ($value as $s_key => $s_value) {
               echo "<td>$s_value</td>";
               }
           echo "</tr>";
       }
       echo "</table>";
       //asort will sort the array $arr on the basis of the second argument(tweets)
       asort($arr,$arr["joeDoe"]["tweets"]);
       //The same as of above table is printed here
       echo "<h1>Sorted Array:</h1><table border='1'>";
       echo "<tr><th>User name</th>
               <th>Tweets</th>
               <th>No. of followers</th>
               <th>Following</th>
               </tr>";
       foreach ($arr as $key => $value) {
           echo "<tr>
               <td>$key</td>";
               foreach ($value as $s_key => $s_value) {
               echo "<td>$s_value</td>";
               }
           echo "</tr>";
       }
       echo "</table>";
   ?>
</body>
</html>

4 Output:

User name Tweets No. of followers Following joe Doe 20000 45 JohnD 62000 123 160 computerSavy myTwitterAccount 1800 15 75 Sor

Add a comment
Know the answer?
Add Answer to:
1. Print out information of PHP use phpinfo() function. 2. Write a program that check and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that check odd / even numbers (from number 1 to 100). Display the...

    Write a program that check odd / even numbers (from number 1 to 100). Display the results within an HTML table with 2 columns: one for odd number and one for even numbers. NUMBERS RESULTS ODD EVEN ODD 2 HINT: use <table> tags to create a table, <th> tags for 'Numbers' and 'Results'. Wrap code PHP inside HTML code. For example: <html> <title>CHECK ODD or EVEN</title> <body> <table> ?php echo "<tr><td>l</td><td>Odd</td</tr>"; </table> </body </html 2. Do the following steps in...

  • Write a PHP program using a ''FOR loop' to compute and print the employee's salary for...

    Write a PHP program using a ''FOR loop' to compute and print the employee's salary for some number of years with a percent increase each year. Your submit button should re-call this page and use PHP to create a table of salaries for each year starting at 1 up to the value of the years variable. So if 'years' is equal to 5, there should be 5 rows in your table. For each year, the salary increases by X%. Make...

  • Write a web program to allow the user to sort a list of things. Use HTML...

    Write a web program to allow the user to sort a list of things. Use HTML and PHP. Your input (HTML) should include a text area the user can type in their list. The output (PHP) should be in the form of a table. Use the explode command to break the input up into an array. $list=explode(PHP_EOL, $stuff); Once you have the text into an array, use the sort function to sort it, and then loop through it and print...

  • Q1. rewrite the exercise on April 4 by adding the following operations: 1) In the php...

    Q1. rewrite the exercise on April 4 by adding the following operations: 1) In the php script, create an associative array named $order that stores the following values: - the number of cheese toppings; - the number of pepperoni toppings; - the number of ham toppings; - the size of the ordered pizza; - the number of the ordered pizza; - the total cost of the order; - the discount rate; - the total cost after the discount. 2) the...

  • Use php Create a file to write a program of 30 city name and populations Using...

    Use php Create a file to write a program of 30 city name and populations Using two files Print using associative array Output should be like Cities: Name. Population Daka. 13 millions

  • This code should be written in php. Write a program that allows the user to input...

    This code should be written in php. Write a program that allows the user to input a student's last name, along with that student's grades in English, History, Math, Science, and Geography. When the user submits this information, store it in an associative array, like this: Smith=61 67 75 80 72 where the key is the student's last name, and the grades are combined into a single space-delimited string. Return the user back to the data entry screen, to allow...

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

  • In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while...

    In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while loop or a for loop to print only odd numbers 1, 3, 5, 7, 9 *tip: you can use range () function, or a condition with ‘break’ (e.g, while count < 10) In python!: Create a program that print out 12 months of a year and associated numbers (e.g., January 1, February 2…). Two lists should be created, and then loop through the list...

  • 1.Write a PHP function that generates a random email. 2.Write a PHP function that generates a...

    1.Write a PHP function that generates a random email. 2.Write a PHP function that generates a random password given the length as a parameter. 3. Run a query that will generate a database named lab4 b. 4.Run a query that will create a table named users, the table will only have three columns, email TEXT and password TEXT, ID INTEGER NOT NULL AUTO_INCREMENT. ID will be the primary key that will be generated for us automatically based on the record...

  • Write a C program to do the following 1) request user to enter 10 integer into...

    Write a C program to do the following 1) request user to enter 10 integer into an array 2) sort the array in ascending order 3) display the sorted array 4) count the number of odd and even number in the array and print out the result 5) add the value of the odd number and even number and calculate the average of the odd and even number. display the result 6) write function addNumber() to add all the number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT