Page 1 of 1

array problem

Posted: Wed Jul 09, 2003 3:31 am
by MeHigh
I have this code:

Code: Select all

<?php
<?php
$limbaje = array(0=>"Perl", 1=>"PHP", 2=>"Python");
$limita = count($limbaje);
for ($i = 0; $i < $limita; $i++)
{
echo "<br>$i => $limbaje[i]";
}
?>
?>
It was suppose to print something like

Code: Select all

0=&gt;Perl
1=&gt;PHP
2=&gt;Python
but all it does is:

Code: Select all

0=&gt;
1=&gt;
2=&gt;
Is it becouse the Register_globals option in php.ini is off and if so, how can make it print the variables without turning the register_globals option ON?

Many thanks in advance

Posted: Wed Jul 09, 2003 4:02 am
by Wayne

Code: Select all

<?php 
$limbaje = array(0=>"Perl", 1=>"PHP", 2=>"Python"); 
$limita = count($limbaje); 
for ($i = 0; $i < $limita; $i++) 
&#123; 
echo "<br>$i => $limbaje&#1111;$i]"; 
&#125; 
?>
you missed the $ off the I variable name in the echo.

Posted: Wed Jul 09, 2003 4:17 am
by MeHigh
thanx a lot

Posted: Thu Jul 10, 2003 6:55 am
by ik
There are more simple ways:

foreach($smth as $key=>$val)
echo '<br>['.$key.']=>'.$val;

Or just use print_r(), as it described in PHP manual:
<pre>
<?php
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x','y','z'));
print_r ($a);
?>
</pre>