Access a variable using a counter as part of the variable name

前端 未结 5 1899
清歌不尽
清歌不尽 2021-01-29 08:52

I tried to do somthing like that:

$cat1 = array(\'hello\', \'everyone\');
$cat = array(\'bye\', \'everyone\');

for($index = 0; $index < 2; $index++) {
echo $         


        
5条回答
  •  故里飘歌
    2021-01-29 08:59

    To echo elements inside arrays, you need to be using

    echo $cat[$index]

    with your example.

    I'm not sure what the $index[1] is supposed to be doing? Maybe I have misunderstood your question.

提交回复
热议问题