store data in array php code example
Example 1: how to store data with php
<?php
//Get a secure filename so no one can get your server files
$username = "myUsername"
$filename = uniqid($username, true).".csv";
//You can change the .csv file to a .txt
//Create the array that stores data. You can replace what is below with what you want
$userInfo = ["username" => $username, "points" => 0];
// Store the data
file_put_contents($filename, serialize($userInfo));
// How to get the data
$userInfo = unserialize(file_get_contents($filename));
print($userInfo["points"]);
// or
print($userInfo["username"]);
//Make sure that ^^^^ matches what is in the array
?>
Example 2: how to store array in variable php
$myArray = array("http://www.marleenvanlook.be/admin.php","http://www.marleenvanlook.be/checklogin.php","etc");
$i = 0;
foreach($myArray as $value){
${'something'.$i} = $value;
$i++;
}
echo $something0; //http://www.marleenvanlook.be/admin.php
Example 3: how to store array in variable php
$something = array(
'http://www.marleenvanlook.be/admin.php',
'http://www.marleenvanlook.be/checklogin.php',
'http://www.marleenvanlook.be/checkupload.php',
'http://www.marleenvanlook.be/contact.php',
);
foreach($something as $key => $value) {
$key = 'something' . $key;
$$key = $value;
// OR (condensed version)
// ${"something{$key}"} = $value;
}
echo $something2;
// http://www.marleenvanlook.be/checkupload.php
Example 4: how to store array in variable php
$data = array(
'something1',
'something2',
'something3',
);
extract($data, EXTR_PREFIX_ALL, 'var');
echo $var0; //Output something1