PHP file as soft DB? -


i want use php include file soft db of 20 elements. actual data collected rrd files , prefer not use mysql 20 elements. file fruits.php elements i'm trying like:

<?php $fruit="apple"; $colour="red"; $fruit="banana"; $colour="yellow"; $fruit="pear"; $colour="green"; ?> 

in recall file, results.php, currenlty have following code recall information fruits.php file:

<?php include 'fruits.php'; $num=count($fruit); $i = 0; while ($i < $num){ echo "<p>my ".$fruit." ".$colour.".</p>"; $i++; } ?> 

since i'm not proper scriptor/programmer, i'm quite blind should different , stupid proper coding. have tried other methods well, 1 included:

$num=glob($fruit); 

any assistance appreciated. confirm output i'd code be:

my apple red. banana yellow. pear green. 

in case, variable $fruit have value "pear", , $colour = "green" because redefine it

 <?php  $fruits = array();  $fruits[] = ["name" => "apple", "colour"=>"red"];  $fruits[] = ["name" => "banana", "colour"=>"yellow"];  $fruits[] = ["name" => "pear", "colour"=>"green"];  ?> 

1st way:

<?php include 'fruits.php'; $num=count($fruits); $i = 0; while ($i < $num){ echo "<p>my ".$fruits[$i]["name"]." ".$fruits[$i]["colour"].".</p>"; $i++; } ?> 

2nd way (much easier):

<?php  include 'fruits.php'; foreach ($fruits $fruit){   echo "<p>my ".$fruit["name"]." ".$fruit["colour"].".</p>"; }  ?> 

where $fruit element of array $fruits


Comments