0
<html>
<body>
<?php
    $array = range(1,10);

    echo 'out func Array for Before : <br />';
    for($i = 0; $i < 10; $i++)
        echo $array[i]; // This Line!!
    echo 'End of Array Found.<br />';

    function my_multiply(&$value, $key, $factor){

        echo 'in func value(Before) - '.$value.'<br />';
        $value *= $factor;
        echo 'in func value(After) - '.$value.'<br />';
    }
    array_walk(&$array, 'my_multiply', 3);

    echo 'out func Array for Aefore : <br />';
        for($i = 0; $i < 10; $i++)
            echo $array[i]; //This Line Too.
    echo 'End of Array Found.<br />';
?>
</body>
</html>

I tried to print array[i] using echo function. but It doesn't print anything!

enter image description here

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
WishSKY
  • 33
  • 6
  • 1
    you missed $ write this way `$array[$i]`; – Talk2Nit Jan 08 '18 at 06:55
  • ```i``` is not a variable. Could you use: $array[$i] – Andrew Nguyen Vo Jan 08 '18 at 06:55
  • PHP 7.2 says: *"Warning: Use of undefined constant i - assumed 'i' (this will throw an Error in a future version of PHP)"*. It used to be a notice in previous versions and your interpreter is probably configured to not report the notices. – axiac Jan 08 '18 at 07:22

1 Answers1

0

You forgot $ near i.

So this:-

echo $array[i];//forgot $ near i

Need to be:-

echo $array[$i];// now $i is correct variable and will work fine

Every-where

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98