function loadarray($arrayname,$file){
    $$arrayname=file("$file");
    }
loadarray("valueFromFile","cars.txt");
echo "($valueFromFile)";

$value from file should at least containt a string "arry", but it is empty.
I started to create many functions, but some of them does not work. this is one of them. What should I learn ?

    You need to [man]return[/man] it in the function definition.

      function loadarray($arrayname,$file){ 
          $arrayname=file("$file"); 
          return $arrayname;
      } 
      loadarray("valueFromFile","cars.txt"); 
      echo "($valueFromFile)"; 

        When you create a variable inside a function its scope is limited to inside the function only. I think you're looking for something more like this:

        function loadarray($file){
           return file($file);
        }
        $valueFromFile = loadarray("cars.txt");
        print_r($valueFromFile); 

        Although that's pretty pointless since the same thing is accomplished just by:

        print_r(file("cars.txt"));
          Sops21;10966497 wrote:

          ]

          Fantastic !
          You fixed my function! πŸ™‚

          ( ( I will mark this thread as solved after I try the function πŸ™‚ ) )

            anakadote;10966500 wrote:

            function loadarray($file){return file($file);}$valueFromFile=loadarray("cars.txt");print_r($valueFromFile);

            This is very interesting solution!
            This could really come handy !

            Print is not the only thing I want to do with array. Since that, it is not pointless.
            I am glad to know your solution πŸ™‚

              I was not noticed about new replyes in my thread. Does it happen often ?

                TryPHP wrote:

                I was not noticed about new replyes in my thread. Does it happen often ?

                What replies were you hoping to get when you stated that you were about to mark this thread as resolved?

                  laserlight;10966509 wrote:

                  What replies were you hoping to get when you stated that you were about to mark this thread as resolved?

                  I was not hoping to get replyes, I was hoping for email notices

                    Sops21;10966497 wrote:

                    -

                    When I tryed it, it did not work, should I make a video on youtube how I did to see whether I did it wrong or not ?

                      anakadote;10966500 wrote:

                      ]

                      This works πŸ™‚
                      But Id like to have a functions that creates variable instead of a variable that contains function πŸ™‚

                        What are you expecting your function to do? What's the desired end result? Please show us a usage example.

                          anakadote;10966603 wrote:

                          -

                          So I want function which I tell variable name and file name and it creaes array from file
                          So I call function

                          loadarray("ArrayOfBananas","bananas.txt")
                          

                          And now I should have array $ArrayOfBananas
                          which is built from file bananas.txt

                          I definitelly like this example

                          function loadarray($arrayname,$file){
                              $arrayname=file("$file");
                              return $arrayname;
                          }
                          

                          And I will call it like this

                          loadarray("ArrayOfBananas","bananas.txt");
                          

                          So I can work with it like this

                          echo "($ArrayOfBananas[0])"; 
                          

                          First banana is yellow with size 20 so it will write "(yellow-20)" to web browser

                          But it does not create array.

                          I do not think Variable scope will help me now, I do not understand it much.

                            OK, you really don't need to create your own function to do what you want. And the example you like won't work and honestly doesn't make sense. Here is what I recommend:

                            <?php
                            
                            $file = 'path/to/file/bananas.txt';
                            $bananas = file($file);
                            
                            echo '(' . $bananas[0] .')';
                            
                            ?>
                              anakadote;10966606 wrote:

                              .

                              This is not the only I want.
                              This was an exaple for what I want so I can make bigger functions after this is gonna work.
                              So it currenty seems I have to use this syntax for my future functions like

                              $cars=loadArrayAndPreapareItForPHPuseAndDeleteLetter52fromEachElementAndMakeFirstLetterBig("cars.txt");
                              

                              If it would work on my wish it would look

                              loadArrayAndPreapareItForPHPuseAndDeleteLetter52fromEachElementAndMakeFirstLetterBig("cars","cars.txt");
                              

                              It would be equal result.

                                I still don't really understand what you're after. If you could provide an example of what cars.txt looks like as well as the output that you want in end after PHP handles it I can probably help.

                                  anakadote;10966608 wrote:

                                  .

                                  I am gonna make it all in exaples, it will take time. Ill post when finished

                                    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 ?