Hi,
I am trying to print a table but I can't.

I have a file called r.php with rules like

<?php 
$rule['ab'] = "afd";
$rule['vf'] = "ghe";
$rule['as'] = "rtg";
?>

and in another file I write

<?php
include_once("r.php");
$a = 'as';
echo $rule[$a];
?>

but it is not printed rtg in my screen

What is wrong ?
Thanks a lot

Member Avatar for diafol

does

echo $rule['as'];

work?

does

echo $rule['as'];

work?

Yes it works, but I need variable $a because takes dynamically the value.

Member Avatar for diafol

Hmm, unfortunate. I was hoping it was a directory issue - I can't see anything wrong with the code.

Hi,

Try this..

r.php

<?php
 
    $rule['ab'] = "afd";
    $rule['vf'] = "ghe";
    $rule['as'] = "rtg";
## something has to carry the rule out of this
    $rules[]    = $rule;
?>

and on the other file

<?php
	include_once("r.php");
## it is costly, memory wise, but this is the only thing I could think of right now
## to get the rule printed out.
	foreach($rules as $show_rule){
		
		echo $show_rule['as'];
	}

?>

Looks like some server setting i just re-created it on mine and works fine. try error_reporting(E_ALL); at the start and var_dump($rule); and even declaring $rule as an array before adding values to it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.