This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by Alex
about 11 years

Where is my syntax error?!

Hi,

In result:

PHP Parse error: syntax error, unexpected T_PRINT in /root/adapter/runners/runner.php(47) : eval()’d code on line 14

index.php

<html>
<p>
<?php
// Create an array and push on the names
// of your closest family and friends
$family_friends = array("Father", "Mather", "Sister", "Dragoev", 
"Ralev", "Veliko");
array_push($family_friends, "Petyo");
// Sort the list
sort($family_friends);
// Randomly select a winner!
$winner = rand($family_friends[0] , count($family_friends) - 1)
// Print the winner's name in ALL CAPS
print strtoupper($winner);

?>
</p>

Answer 5151853d8f002e2b68001cd2

2 votes

Permalink

points
about 11 years

Answer 514fe05134cba31136000060

1 vote

Permalink

there’s a “;” missing at the end of line 14. btw, the rand function’s first parameter should be int, but you use a string.

points
Submitted by icesyc
about 11 years

Answer 51501559afb1438f500003ff

0 votes

Permalink

Ok, but now where I wrong?!

<html>
<p>
<?php
// Create an array and push on the names
// of your closest family and friends
$users = array("Veliko", "Dragov", "Ralev");
array_push($users, "Petyo");
// Sort the list
$sort_users = sort($users);
// Randomly select a winner!
$winner = rand(0, count($sort_users) - 1);
// Print the winner's name in ALL CAPS
print strtoupper($winner);
?>
</p>

Result

0

points
Submitted by Alex
about 11 years

Answer 515074e41f6c225220000ce6

0 votes

Permalink

You need the print winner’s name:

$winnerName = strtoupper($names[$winner]);
print $winnerName;
points
Submitted by Dang Thanh
about 11 years

1 comments

Alex about 11 years

Thanks a lot!

Answer 5157378fa568f96b6700005c

0 votes

Permalink

ok where am i wrong, i get this error message:

PHP Warning: rand() expects parameter 1 to be long, string given in /root/adapter/runners/runner.php(47) : eval()’d code on line 10 PHP Notice: Undefined index: in /root/adapter/runners/runner.php(47) : eval()’d code on line 11

my code:

points
Submitted by Tom
about 11 years

1 comments

Péter Bence Stumpf about 11 years

$array[1] is not an integer, it is the second element of your array (fuzzy after sort). You obviously can not generate a random integer between fuzzy and 4. Instead of $array[1] in random, use 0.

Answer 522ef4b7f10c600ba8001c25

0 votes

Permalink

// this is right ============================

points
Submitted by stuey06
over 10 years

Answer 532ab51852f8636e7c00179b

0 votes

Permalink

$familyfriends = array(); array_push($familyfriends, “Matt”); array_push($familyfriends, “Momo”); array_push($familyfriends, “Comit”); // Sort the list sort($familyfriends); // Randomly select a winner! // Print the winner’s name in ALL CAPS print strtoupper($familyfriends[rand(0, count($familyfriends) - 1)]);

points
Submitted by rishabh bhargav
about 10 years

1 comments

rishabh bhargav about 10 years

please put underscore in line 1 & 2 like (array_push)..thank u..

Answer 53cd66c852f863a65f000363

0 votes

Permalink

points
Submitted by Rich Halsey
over 9 years

Answer 547422d69c4e9d74a4000fc5

0 votes

Permalink

points
Submitted by Daniel Daniel
over 9 years

Answer 557014cad3292f883d000365

0 votes

Permalink

points
Submitted by sachin cinas
almost 9 years