J
J
Jony13372015-10-17 12:42:37
PHP
Jony1337, 2015-10-17 12:42:37

Problems with array in php?

There is an array

<?php

  $quotes[] = 'text1';
    $quotes[] = 'text2';
    $quotes[] = 'text3';
    $quotes[] = 'text4';
    $quotes[] = 'text5';
 srand ((double) microtime() * 1000000);
    $rs = rand(0,count($quotes)-1);

when I want to display $r I should display randomly from text1 to text5 but I should display either 0 or 1 or 2 and not the text I need
here is the output code
<?php
$html = <<<HERE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>$pagina</title>
<meta property="og:title" content="  $rs   " /> 
<meta property="og:description" name="description" content="$descriere">
<meta property="og:type" content="photo" />
<meta property="og:image" content="http://site.ru/images/$userin.png" />
<script type="text/javascript">  
  location.replace("http://site.ru/start.php");  
  </script>
</head>
<body>
</body>
HERE;
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2015-10-17
@Jony1337

you output your random number, not an array element

<meta property="og:title" content="  $quotes[ $rs ]   " />
or
$rs = $quotes[ rand(0,count($quotes)-1) ];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question