Click here to Skip to main content
14,690,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
a) With reference to the following:
 $sch = array(
 ‘T’ => “SFD”,
 ‘L’ => “SOT”,
 ‘H’ => “MASSCOM”,
 ‘Hy’ => “BBA”
 );
i. There are two (2) ways in PHP to create an array: INDEX and ASSOCIATIVE. In the $sch array example above, one of the types is used. Rewrite the $sch array using the other type.

ii. Write a PHP code to output the content of the $sch array, each one on a separate line, for the one you have written above (b)

b) Session variables uses associative array to keep track of users. Write down a simple piece of PHP code using session which test to find out whether the user of current_page.php is logged in or not using session. In your code, if the user is logged in, render the said page else redirect this user to the login.php


What I have tried:

<?php
$sch = array(
 ‘T’ => “SFD”,
 ‘L’ => “SOT”,
 ‘H’ => “MASSCOM”,
 ‘Hy’ => “BBA”
 );
Posted
Updated 20-Jun-20 14:19pm
v2

1 solution

ok ..
Quote:
i. There are two (2) ways in PHP to create an array: INDEX and ASSOCIATIVE. In the $sch array example above, one of the types is used. Rewrite the $sch array using the other type.


so what type of array is being declared here ?
$sch = array(
 'T' => "SFD",
 'L' => "SOT",
 'H' => "MASSCOM",
 'Hy' => "BBA"
 );


The first part of the question wants you to re-write the definition of $sch using the other way of defining arrays in PHP .. maybe you need to look at PHP Arrays[^] for example, to figure out what you have, vs what you need
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900