I am using phpMyAdmin for collecting data I have extracted the data in the format of a PHP Array Now I would like to extract the data in the PHP array in order to put them in a text file. I suppose I have to do this in another PHP file I was wondering how can I access the array of the first file ?
To do this you can use includes. When you include the file the variable scopes will continue into the file.
index.php
<?php
$array = [1,2,3,4]
include('my_file.php');
?>
my_file.php
<?php
print_r($array);
?>
Documentation: http://php.net/manual/en/function.include.php
You can use the php file you used to retrieve the data. Ther's no need to code this in another file.
If you want to store an array into a file, I would suggest you to encode this in some sort of string with json_encode() or serialize(). You can then recover your array using json_decode() and unserialize()
Lets call the file which contains your PHP array data_array.php
<?php
$data_array = {1, 2, 3, 4, 5}
?>
Then in the PHP file where you want to use your data.
<?php
require_once("data_array.php");
print_r($data_array);
?>
We included the data_array.php
file and printed the $data_array
array variable from the data_array.php
file.
Though I would suggest you to learn to use SQL client like PDO itself in PHP so you do not have to manually fetch the data with phpMyAdmin.