Jump to content

Very simple random array


3raser

Recommended Posts

I'm learning more stuff, and I don't understand why this isn't working. It's not returning any results.

 

test_index.php

<?php
include ("test_functions.php");

$array = array("Welcome", "Welcome back", "Good-bye");

echo ParseTest($array, $output);
?>

 

test_functions.php

<?php

function ParseTest($array) {
$output = array_rand($array,1);
echo "The random result returned: ". $array[$output['0']] ."";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/205225-very-simple-random-array/
Share on other sites

You're not returning anything from the function. Replace the "echo" with a "return":

<?php
function ParseTest($array) {
    $output = array_rand($array,1);
    return "The random result returned: ". $array[$output];
}
?>

 

Also, your function has only one parameter, so you should call it using one parameter.

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.