suttakan mongkon
suttakan mongkon

Reputation: 111

how to use variable variables PHP function on my code?

Normally i use this code and it's will be echo work good.

<?PHP 
echo $row->test_column_1;
?>

But when i tyied to use this code, it's not echo any data. How can i do ?

<?PHP
$i = "1";
echo ${'row->test_column_' . $i};
?>

Upvotes: 1

Views: 33

Answers (1)

Theodore Brown
Theodore Brown

Reputation: 957

You can access a dynamic property name like this:

<?php
$i = "1";
echo $row->{'test_column_' . $i};

Upvotes: 2

Related Questions