Avatar of firekiller15
firekiller15 asked on

what happen to my code, why cannot get result

PHP
*************config.php**************
$studentPull=1;
$student1=ASIAN;
$student2=EUROPE;
$student3=MIDDLE_EAST;
$MapUniverseFile=array('$student1','$student2','$student3');


***************MAIN**********************
function GETSTUDENTLIST()
{
require("config.php");
if ($studentPull)             // get description from config file
  $mapstudent = $MapstudentFile;
  echo"this is  " .$mapuniverse;
}

newtest->GETSTUDENTLIST();

ouput i get is
---------------
this is array

how to solve?
PHP

Avatar of undefined
Last Comment
nplib

8/22/2022 - Mon
BrianGEFF719

Questions:

1) is GETSTUDENTLIST in a class?
2) What the hell is $mapuniverse?

Temporary Solutions:

  Try changing this line:
    echo"this is  " .$mapuniverse;

  To
    print_r($mapuniverse);
ASKER
firekiller15

2) What the hell is $mapuniverse?
sorry typo

is echo $mapstudent

i had try using print_r($mapuniverse)
but the result i get is
array([0]=>$student1,([1]=>$student2);

1) is GETSTUDENTLIST in a class?
yah in a class
nplib

it's saying "Array"

because it is an array

if you want to show it as a list, you need to loop through the array
function GETSTUDENTLIST()
{
require("config.php");
if ($studentPull)             // get description from config file
  $mapstudent = $MapstudentFile;
  foreach ($mapstudent as $ms) {
    echo"this is $ms<br />";
  }
}
 
newtest->GETSTUDENTLIST();

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
firekiller15

received this message
Warning: Invalid argument supplied for foreach() in C:\wamp\www\test.php on line 100
ASKER
firekiller15

Ok i fix the error message.
i want to print out the new sentence in a new line
i do like this
echo"this is" .$ms. "\r\n";
but still fail why
ASKER CERTIFIED SOLUTION
nplib

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question