For some weird reason, my echo function isn't outputting anything. The code is very simple, therefore I just don't see why it wouldn't output correctly.
<h2>First function:</h2><br>
<?php
function splitSort($String) {
$splitString = explode (" " , $String);
sort($splitString);
return $splitString;
}
?>
<div>
<?php
$question1 = $splitSort("Dog Pig Cat Mouse Cattle");
echo 'Example of Question 1 for string "Dog Pig Cat Mouse Cattle", the method returns :' . $question1;
?>
</div>
I have fixed the erros I found, this is the correct code. Note: the variable $question1
is an array
, I have printed out the first element of the array for the purpose of this example.
<h2>First function:</h2><br>
<?php
function splitSort($String) {
$splitString = explode (" " , $String);
sort($splitString);
return $splitString;
}
?>
<div>
<?php
$question1 = splitSort("Dog Pig Cat Mouse Cattle");
echo 'Example of Question 1 for string "Dog Pig Cat Mouse Cattle", the method returns :' . $question1[0];
//question1 is an array containing: "Dog, Pig, Cat, Mouse, Cattle". With [0], like the example you will get Dog.
?>
</div>
In case you still don't get anything, any of these (or more) could be your answer why it is not working
http://localhost/myfile.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.