anakadote;10966603 wrote:.
This is a working example:
<?php function br($HowMany){for($p=0;$p<$HowMany;$p++){echo"<br>";}}
/**
* title: Example script for PHP forum
*/
// Function to echo array
function echoArrayInHtml($arrayVariable,$arrayName){
echo '<font face="Lucida Console" size="-2">';
echo "Array: $arrayName<br />(<br />";
$spaces=" ";
$rn="\r\n";
foreach ($arrayVariable as $k => $v){
echo "$spaces"."[$k]=>$v"."<"."$rn<br />";
}
echo ")";echo '</font><br />';
}
// Function to delete new lines from file array so PHP can use it with no worries
function arrayToPHP($array){
foreach ($array as $k => $v) {
$searchfor=strpos($v,"\r\n");
if(empty($seachfor) and $seachfor!==0){
$tmp[$k]=substr($v,0,-2);
}
}
if(empty($seachfor)){
$tmp[$k]=$v;
}
return $tmp;
}
// Function to make first letter big in array
function firstToBigInArray($array){
foreach($array as $k => $v) {
$tobig=strtoupper(substr($v,0,1));
$rest=substr($v,1,99999);
$tmp[]=$tobig.$rest;
}
return $tmp;
}
// Function to Delete string "*" from array
function deleteStarFromArray($array){
foreach($array as $k => $v){
$position=strpos($v,"*");
if (!empty($position)){
$part1=substr($v,0,$position);
$part2=substr($v,$position+1,99999);
$tmp[$k]=$part1.$part2;
}
if($position===0){
$tmp[$k]=substr($v,1,99999);
}
if (empty($position) and $position!==0){
$tmp[$k]=$v;
}
}
return array_values($tmp);
}
// Function to load Array from file and delete "\r\n" and Delete Letter "*" from Each Element And Make FirstLetter Big
function arrayFromFileNoRNnoStarFirstLetterBig($file){
$array=file($file);
$array=arrayToPHP($array);
$array=deleteStarFromArray($array);
$array=firstToBigInArray($array);
return $array;
}
// Main script:
br(19);
//I want to make array from file names.txt and modify it so I call my function
$NamesArray=arrayFromFileNoRNnoStarFirstLetterBig("names.txt");
// I want to send this array to web browser so:
echoArrayInHtml($NamesArray,"Names");
?>
Source and output in the picture (with code)

I was able to create it,because you helped me.
This way of using functions has folowing steps:
1.Make variable
2.Call function to fill variable
__example:
$NamesArray=arrayFromFileNoRNnoStarFirstLetterBig("names.txt");
(Fill variable by result of function)
I am looking for this way:
1.Call function that will create filled variable
__example:
arrayFromFileNoRNnoStarFirstLetterBig("NamesArray","names.txt");
(Create modified array from names.txt)
In the example I use function echoArrayInHtml I can use it the way I like, but it does not create variable/s so it is simple function.
How to use functions the way I am looking for ?