문제

stdClass Object
 (
   [tip1] => Array
    (
        [text] => <p>Test text</p>
        [format] => 1
    )
)

I am trying to loop of object of objects with array

for ($i=1;$i<=10;$i++)
{
  echo $fromform->{'tip$i'}['text'];
}

never worked?

도움이 되었습니까?

해결책

Use double quotes,

echo $fromform->{"tip$i"}['text'];

Or like this wiht single quotes,

$fromform->{'tip'.$i}['text'];

다른 팁

php variables never get parsed within single quoted

replace it with double quote

for ($i=1;$i<=10;$i++)
{
   echo $fromform->{"{tip$i}"}['text'];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top