0

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

4
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by Biiim
0

does

echo $rule['as'];

work?

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

0

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

0

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'];
	}

?>

Edited by veedeoo: n/a

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.