Affichage des articles dont le libellé est Active questions tagged arrays - Stack Overflow. Afficher tous les articles
Affichage des articles dont le libellé est Active questions tagged arrays - Stack Overflow. Afficher tous les articles

vendredi 31 juillet 2015

json_decode multidimensional from database

I have this json saved in my database in a column called 'price' with the type of 'text'.

{
  "desks": {
    "Dedicated Desk": "$400 mo"
  },
  "private offices": {
    "1 Person": "$550 mo",
    "2 Person": "$1100 mo",
    "3 Person": "$1600 mo",
    "4 Person": "$2100 mo",
    "6 Person": "$3300 mo"
  },
  "flexible membership": {
    "Starting at": "$45 mo",
    "Every Extra Day": "$50 Day"
  }
}

I then make a call from PHP to return my all the fields in my database and encode them as json.

$json = json_encode($response,JSON_PRETTY_PRINT);
echo $json;

$response is the response from the database. When I var_dump on $response I get

array(22) {
    [0]=>
      object(stdClass)#6 (38) {
        [...]

        ["price"]=>
        string(242) "{"desks":{"Dedicated Desk":"$400 mo"},"private offices":{"1 Person":"$550 mo","2 Person":"$1100 mo","3 Person":"$1600 mo","4 Person":"$2100 mo","6 Person":"$3300 mo"},"flexible membership":{"Starting at":"$45 mo","Every Extra Day":"$50 Day"}}"

        [...]
      }
    [...]
}

When I echo the result from json_encode i get

[
    {
        [...]

        "price": "{\"desks\":{\"Dedicated Desk\":\"$400 mo\"},\"private offices\":{\"1 Person\":\"$550 mo\",\"2 Person\":\"$1100 mo\",\"3 Person\":\"$1600 mo\",\"4 Person\":\"$2100 mo\",\"6 Person\":\"$3300 mo\"},\"flexible membership\":{\"Starting at\":\"$45 mo\",\"Every Extra Day\":\"$50 Day\"}}",

        [...]
    },
    [...]
]

My problem is json_encode is taking the json from the database and formatting it as a string. I am trying to get it to format it as part of a multidimensional json structure. This is what im trying to achieve:

[  
   {  
      "price":[  
         {  
            "desks":{  
               "Dedicated Desk":"$400 mo"
            },
            "private offices":{  
               "1 Person":"$550 mo",
               "2 Person":"$1100 mo",
               "3 Person":"$1600 mo",
               "4 Person":"$2100 mo",
               "6 Person":"$3300 mo"
            },
            "flexible membership":{  
               "Starting at":"$45 mo",
               "Every Extra Day":"$50 Day"
            }
         }
      ]
   }
]

Any help would be appreciated. Running latest version of php.

How to assign array into variable in jquery

The original and working array is this:

 var columns =[{
        name: 'level',
        minWidth: '200px'},
        {
        name: 'subject',
        minWidth: '70px'},
        {
        name: 'catid',
        minWidth: '70px'}],

However, I want to use if else statement to assign different array for different 'target' value. So I tried as below but it doesn't seem to supply the array correctly to the 'columns' variable.

 var useThis=[];
        if(target=="subject")
        {
            useThis = {
            name: 'level',
            minWidth: '200px'},
            {
            name: 'subject',
            minWidth: '70px'},
            {
            name: 'catid',
            minWidth: '70px'};

        }
        else
        {
            useThis = {
            name: 'level',
            minWidth: '200px'};

        }
var columns="["+useThis+"],";

How do I assign array correctly with if else statement?

Modify global variable array through a bash function, passing the function the name of the variable as a string

Dear I need something to help me in this. I'm trying to modify a global array through a function , using an auxiliary variable called "array". I would like to modify the global array "config " using a function that takes a string with the name of the variable " config".

I'm trying the following but I have not gotten results .

declare -A config

function testABC {
    array=${1}[@]
    array["key"]="value1"
    array["key2"]="value2"
}

testABC "config"
echo ${config["key"]}
echo ${config["key2"]}

#desired output:
#value1
#value2

My version of bash is 4.2.45

regards.

PHP Database Incremental Search using Array

I am learning coding, but I am wanting to make an interactive roster for a local youth camp where upon registering a new camper's personal information (in database is 'name', 'birth_year', 'hobbies', 'favorite_subject', 'spirit_animal_explanation' and 'contact_information') the camper can select a "group-me" button that will display the profiles of other campers who have similar hobbies and spirit animals as them as well as being within the same age group (11-13yrs, 14-16yrs,etc).

To achieve this, when a camper enters in his/her information, it is first saved into the database. I then query a SELECT syntax that takes the info from the 'hobbies' and 'spirit_animal_explanation' columns of the camper and filter it of unwanted words and put them in an array (so for 'hobbies' if the camper says "I like Running and Jumping" the the filter will array will only print_r Array([0]=>running[1]=>jumping).

I then array_merge the two filtered arrays into one so I easily manage the search (some campers like mixing up the hobbies into the spirit_animal_explanation so by having a single reference array for both columns the search can be easier) leaving me with a $compiled variable containing the two merged arrays.

Now the part(s) I am Struggling with: I am able to prepare the reference array for the search, but I don't know the query syntax to begin the search or scanning the 'hobbies' and 'spirit_animal_explanation' columns of every user using the reference array. From previous suggestions I've read up on JOIN queries but I don't see a point in making two tables because the elements of the reference array are not fixed/constant for every camper that executes the search. Also, I have no idea how/when I should add in the age conditional. Finally, the improve latency I want the system to look for the first 10 matching users on the first search session, then the next ten users on the second, etc. How can I go about doing this?

Python "numpy.dtype" structure for reading binary to "list" with "numpy.fromfile"

+++ WARNING, THE FOLLOWING CONTAINS VERY UGLY PROGRAMMING +++

+++ PLEASE HELP!!! +++

Hey, I am playing around quit a long time with my read in routines and I still not have figured out a good and fast way!

I have something like this: A huge binary file, which I want to slice down to a numpy-array!

I created this structure to read in fromfile a certain amount of bytes:

    mydt = numpy.dtype([
                       ('col1', np.uint64),
                       ('col2', np.int32),
                       ('cols3_56', np.float32, (53,))
                       ])

reading that like this:

data_block = numpy.fromfile(openfile, dtype=mydt, count=ntimes)

What I am getting out is something like this:

[(88000031189210L, 1, [-1000.0, -1000.0, -1000.0, -2.0, -2.0, -2.0, 65004000.0, 0.0, 760680000.0, 0.0, 0.12124349921941757, 0.04971266910433769, 2328.39990234375, 0.00013795999984722584, 0.0, 0.0, -1.0, -1.0, -1.0, 65004000.0, -1.0, 760680000.0, 0.0, 0.0, -1.0, 825680000.0, 0.0, -1.0, -1.0, -1.0, 157630.0, 0.0, 756310.0, 0.0, -1.0, -1.0, 0.0, 5.250500202178955, 0.0, 5.250500202178955, -13.602999687194824, -16.760000228881836, -17.283000946044922, -16.95800018310547, -17.513999938964844, -17.57200050354004, -13.657999992370605, -16.77199935913086, -17.291000366210938, -16.9689998626709, -17.520999908447266, -17.57200050354004, 1.0]), [(88......1L, 1, [-1000.0, ....]), ....

then I extend this datablock to my array

data_block_array.extend(data_block)

... and this million of times ....

I want now to access two things:

  • the 2th element in the above structure (in this example "1") for the entire data array which is a couple of millions times the above mentioned array
  • the 8th (in total the 12th) element in the 53-column data block for the entire array, again millions of substructures!

I figured that out with doing some loops over a count:

 i=0           
 while i<count:
     self.data_array[i,element1] = data_block_array[i][1]
     self.data_array[i,element8] = data_block_array[i][2][13]  

which is incredible slow ... I would like to develop a very fast and easy way to filter my data that way and extract the columns I am interested in. Appreciate some advise and insights!

Sending a dynamic range to a function

Newbie here, so please bear with me. I'm just not getting something about properly putting a dynamic column of values into an array.

The following lines of code work properly for me:

Set RangeD = Sheets("Data").Range("D2:D15")
unique2chan = UniqueItems(RangeD, False)

RangeD is the range I will pass to the function, called "UniqueItems". "unique2chan" is the array of values that will be returned by UniqueItems.

The assumption above is that the values always run from D2 to D15. But for these data, the range's length can vary on each run. (All values will be consecutive in the column, no spaces.)

Here's my question: How do I put a changing number of values into an array that I can pass to my function? I added a counter that tells me how many rows are filled in the column, so if there are 12 values in the column (plus the header), I have a counter that will read 13. How can I use that number to define a range of all the values (minus the header) that I can put into an array to pass to my function?

Any help is appreciated. I've tried a bunch of things I've found on the net, but everyone seems to have a different approach, and I haven't found one that worked for me.

XML parsing in a function and return data in an array list - java [on hold]

I need to read an xml in a method and use that data to drive selenium webdriver script. I am able to read the xml data in to a Arraylist and print the contents in the console. I am also returning ArrayList in the method. I am just struggling to use that returned data in my selenium method for different browser actions(type, click etc). This is my read method which is main method of my class

public static ArrayList main(String[] args) {

    ArrayList<String> testData = null;
    try {
        testData = new ArrayList<>();

        File fXmlFile = new File("C://Javaseleniumworld/Book.xml");
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(fXmlFile);

        //optional, but recommended
        //read this - http://ift.tt/IJO9S6
        doc.getDocumentElement().normalize();

        System.out.println("Root element :" + doc.getDocumentElement().getNodeName());

        NodeList nList = doc.getElementsByTagName("staff");

        System.out.println("----------------------------");

        for (int temp = 0; temp < nList.getLength(); temp++) {

            Node nNode = nList.item(temp);

            System.out.println("\nCurrent Element :" + nNode.getNodeName());

            if (nNode.getNodeType() == Node.ELEMENT_NODE) {

                Element eElement = (Element) nNode;

                System.out.println("firstname : " + eElement.getAttribute("id"));
                System.out.println("server : " + eElement.getElementsByTagName("firstname").item(0).getTextContent());
                String FirstName = eElement.getElementsByTagName("firstname").item(0).getTextContent();
                testData.add(FirstName);
                System.out.println("server : " + eElement.getElementsByTagName("lastname").item(0).getTextContent());
                String LastName = eElement.getElementsByTagName("lastname").item(0).getTextContent();
                testData.add(LastName);
                System.out.println("Array List" + testData);
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return testData;
}

Knockoutjs "foreach" equivalent for non array objects

I've been using Knockoutjs for a while, but there is something I haven't been able to solve and I'm sure there must be an easy way to do it.

I really like nesting objects, using "foreach" on the html and then accessing each of these object's property directly. That way it keeps the code simple and clear.

The problem is that sometimes I use an observableArray to hold only one element in order to use the "foreach way" that I mention.

Is there other way of saying "I'm now within this scope", same behaviour as "foreach".

Example: here

<body>
    <!-- ko foreach: people -->
        <div data-bind="text: name">name</div>
    <!-- /ko -->
    <br />

    <!-- here I would like to say I'm inside 'importantPerson' and therefore name is a property of importantPerson -->
    <!-- <div data-bind="text: name">name (important)</div> -->
    <br />
</body>

Array element checking in swift

Currently implementing a favourite function to my application which is based on quotes. I would like to perform a check for if the user has already saved an element to an array. If they have, I would change a favour button to unfavour button.

   var favouriteQuotesArray: [String]? = NSUserDefaults.standardUserDefaults().objectForKey("thekey") as? [String]

    func makeQuoteFavourite() {
        if favouriteQuotesArray == nil {
            favouriteQuotesArray = []
        }
        let currentQuote = dreamFact.dreamArray[factIndex]
        favouriteQuotesArray!.append(currentQuote)
        NSUserDefaults.standardUserDefaults().setObject(favouriteQuotesArray!, forKey: "thekey")
    }

    @IBAction func favour(sender: AnyObject) {

        if liketext.currentTitle == "Like"{

            liketext.setTitle("Unlike", forState: UIControlState.Normal)

     makeQuoteFavourite()


        } else if liketext.currentTitle == "Unlike" {

            liketext.setTitle("Like", forState: UIControlState.Normal)


        }

See the issue at currenttitle, the dependency on upon the text which is unreliable because if the user reopens the app, the element would still be saved instead of starting out with the default unlike. If the element is found in the array. How would I perform a search inside my favouriteQuotesArray if the element exists like:

if elementfound statement {

button.settitle(unlike)
removearrayatindex statement.

} else {
button.settitle(like)
makeQuoteFavourite()
}

How would the array checking statement look like? P.S If you can please give tips on building the delete class?

Copying and Referencing of NSObjects iOS

So for a while I have been working on this app - in which contains a folder-like structure of objects which have properties of arrays that can contain the same type of object, which in turn can contain more of this object, etc. These objects are called groups. In a shared data class I have a mater group object called mainGroup, and a property of my data class called selectedGroup to facilitate the display of data. These group objects can be modified, so for a considerable chunk of time I tried to develop a solution for getting the path through all of the arrays to the desired object, all the while having no clue about copying and that assigning one array equal to the other does not create a deep copy, just some kind of reference. The code was logically sound, but in it after a while I noticed that deleting things in the selectedGroup’s array property had the same effect on the actual master copy, which did some wonky things to my app.

I did some googling and figured out that I was not actually creating a whole new array, just referencing it some how. I’m still confused on this next part though. I thought that setting one array equal to the other would have the same effect as calling copy on it - and when I replace or delete objects in one array the other is affected. So what exactly is the compiler doing when you set two arrays equal to each other? Shouldn’t it just populate the new array with the pointers to the objects in the old array, not just reference the array itself? And how come that when doing this same operation with objects such as NSStrings you do not see the same effect? Lastly, what other objects have this same behavior as the NSArrays?

Creating multiple arrays within a for loop (Python)

I'm currently having an issue with numpy arrays. If this question has already been asked elsewhere, I apologize, but I feel that I have looked everywhere.

My initial issue was that I was attempting to create an array and fill it with multiple sets of station data of different sizes. Since I cannot fill the same array with data sets that vary in size, I decided I need to create a new array for each station data set by defining the array inside the for loop I'm using to iterate through each station data set. The problem with this is that, while looping through, each data set will overwrite the previous data set, returning only the final instance of the for loop.

Then, I tried using the + and then the join operations to concatenate a new title for each array, but turns out that is illegal when defining arrays. This is the instance of the program where each data array overwrites the previous one. Note that not all the code is included and that this is part of a definition.

for k in range(len(stat_id)):

    ## NOTE - more code precedes this final portion of the for loop, but was
    ## not included as it is unrelated to the issue at hand.

    # Bring all the data into one big array.
    metar_dat = np.zeros((len(stat_id),len(temp),7), dtype='object')
    for i in range(len(temp)):
        metar_dat[k,i] = np.dstack((stat_id[k], yr[i], month[i], day[i], time[i], temp[i], dwp[i]))
    #print np.shape(metar_dat[k])
    #print metar_dat[k]

#print np.shape(metar_dat) # Confirm success with shape read.
return metar_dat

Upon running and printing the array from this definition, I get this (two empty arrays and a final filled array):

[[[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
..., 
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]]

[[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
..., 
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]]

[[\TZR 2015 7 ..., 2342 58 48]
[\TZR 2015 7 ..., 2300 59 47]
[\TZR 2015 7 ..., 2200 60 48]
..., 
[\TZR 2015 7 ..., 0042 56 56]
[\TZR 2015 7 ..., 0022 56 56]
[\TZR 2015 7 ..., 0000 56 56]]]

My question is this: how can I create an array for each set of station data such that I do not overwrite any previous data? Or how can I create a single array that contains data sets with varying numbers of rows? I am still new to Python (and new to posting here) and any ideas would be much appreciated.

Find() for embed document in mongodb

I have a mongodb for a photo albums. Some photos could be 'special'. So here is part of my db, a album:

{
        "_id" : ObjectId("55bc30befd401b12108b45a8"),
        "name" : "Vacation",
        "criate_at" : "2015-07-31",
        "photos" : [
                {
                        "uri" : "portfolio/h2171874c6e31bab44bed7df8c8ae91a.jpg",
                        "special" : true,
                        "criate_at" : "2015-07-31"
                },
                {
                        "uri" : "portfolio/o2171874c6e31bab44bed7df8c8ae91a.jpg",
                        "special" : false,
                        "criate_at" : "2015-07-31"
                },
                {
                        "uri" : "portfolio/o2171874c6e35bab44bed7df8c8aeq1a.jpg",
                        "special" : false,
                        "criate_at" : "2015-07-31"
                },
                {
                        "uri" : "portfolio/o2171874c6e31bab44bed7df8c8ae23a.jpg",
                        "special" : true,
                        "criate_at" : "2015-07-31"
                }
        ]
}
{
        "_id" : ObjectId("55bc30befd401b12108b4599"),
        "name" : "Zoo",
        "criate_at" : "2015-07-31",
        "photos" : [
                {
                        "uri" : "portfolio/h2171874c6e31bab44bed7df8c8ae933.jpg",
                        "special" : true,
                        "criate_at" : "2015-07-31"
                },
                {
                        "uri" : "portfolio/o2171874c6e31bab44bed7df8c8ae93f.jpg",
                        "special" : false,
                        "criate_at" : "2015-07-31"
                }
        ]
}

I want get only all special photos. I want this result:

{
        "_id" : ObjectId("55bc30befd401b12108b45a8"),
        "photos" : [
                {
                        "uri" : "portfolio/h2171874c6e31bab44bed7df8c8ae91a.jpg",
                        "special" : true,
                        "criate_at" : "2015-07-31"
                },
                {
                        "uri" : "portfolio/o2171874c6e31bab44bed7df8c8ae23a.jpg",
                        "special" : true,
                        "criate_at" : "2015-07-31"
                }
        ]
}
{
        "_id" : ObjectId("55bc30befd401b12108b4599"),
        "photos" : [
                {
                        "uri" : "portfolio/h2171874c6e31bab44bed7df8c8ae933.jpg",
                        "special" : true,
                        "criate_at" : "2015-07-31"
                }
        ]
}

I tried various queries, but nothing... This query give me the first special photos of each album.

db.albuns.find({'photos.special':true},{'photos':{$elemMatch:{'special':true}}}).pretty()

There is any way to get only all specials photos ?

Select rows where jsonb array contains any string in array

This is my SQL so far:

select * from table where table.json_info @> '{"search_tags":["hello", "world"]}'

And this works if the row has BOTH hello and world in the search_tags

I'm wondering if there is a way to include rows that have EITHER hello OR world and of course those that have both.

Thanks to all ahead of time!

Lodash search by startswith in an array

I'm creating a simple search that searches an array of objects that starts with a string passed from an input.

So I have this:

var items = [
    {id: 1, tags: ['foo']},
    {id: 2, tags: ['fish', 'ball']},
    {id: 3, tags: ['bar', 'goo']},
];

input.on(function(e) {
    var test = _.filter(items, function(item) {
         return _.includes(_.pluck(items, 'tags'), input.val());
    });
    console.log(test);
});

This always returns an empty array, I think i'm missing startsWith, how do I use it here in my implementation, or is there a better way of doing search like this?

Store entire line of text file in array line by line (not word by word; include spaces)

I am writing a program where the contents of a text file will be stored in an array line by line. I have it working, but it's only storing one word at a time.

  try ( Scanner fin = new Scanner ( new File("toDoItems.txt") ); ) 
    {
    for (int i = 0; i < listCount && fin.hasNext(); i++) 
          {
          textItem[i] = fin.next();
          }
    }

The listCount variable stores how many lines to read from the file, from the top. Instead it is telling it how many words to read. What can I do to read the entire line into the Array, without knowing how long each line may be?

I set the array size to much larger than I need and I am using the following to display the items one line at a time and only displaying the items in use (so to avoid a long list of nulls)

    for (int i = 0; i < listCount; i++) 
          {
              String temp = textItem[i];
              System.out.println(temp);
          }

(For this I am restricted to arrays only. No Arraylists or lists)

Note: Most similar questions I could find are only attempting to store lines that contain a single word.

PHP function returning NULL instead of array

I call a function that does some recursion and is supposed to return an array. In fact, a var_dump immediately before the return statement in the called function evinces the array; however, a var_dump of the results from the calling function reveals NULL instead of the array.

Here's the calling function.

<?php  

// configuration
require_once("../includes/config.php");
require_once("../includes/getParentNodes.php");  

$bottomNode = 17389;
$chain = [];
$chain[] = $bottomNode;
$results = getParentNodes($bottomNode,$chain);

var_dump($results); ?>

Here's the called function.

<?php

function getParentNodes($node, $results)
{
    $select = query("SELECT parent_id FROM classifications WHERE node_id = ?", $node);
    $parent = implode("",$select[0]);
    if (!empty($parent))
    {
        $results[] = $parent;
        getParentNodes($parent,$results);   
    }
    else
    {
        return $results;
    }
}
?>

If I place a var_dump immediately preceding the return call, I get the following.

Array
(
    [0] => 17389
    [1] => 17386
    [2] => 17334
    [3] => 16788
    [4] => 15157
    [5] => 10648
    [6] => 3962
    [7] => 665
    [8] => 39
    [9] => 1
)

However, the var_dump in the calling function produces a NULL.

I've read the manual and the related posts, but none shed light on this problem. Any help would be much appreciated.

Add items to an empty array [duplicate]

This question already has an answer here:

I have learned that to declare an empty array you do:

int myArray = new int[0]

But how do I add items to this array. For example, how would I add the integers 31, 35, 37?

Sorting grouped multi-dimensional array by value

$data = array(
    'apple' => array(
        0 => array('sort'=>4, 'name'=>'apple_4'),
        1 => array('sort'=>10, 'name'=>'apple_10'),
        2 => array('sort'=>5, 'name'=>'apple_5'),
        3 => array('sort'=>1, 'name'=>'apple_1')
        ),

    'orange' => array(
        0 => array('sort'=>4, 'name'=>'orange_4'),
        1 => array('sort'=>10, 'name'=>'orange_10')
        )
    );

Need assistance sorting multi-dimensional array. For the array above, I would like to sort the contents of each group in descending order by the 'sort' value. The group's keys should remain in tact (apple, orange) but content's keys are not important.

Data should be ordered:

  • apple
    • apple_10
    • apple_5
    • apple_4
    • apple_1
  • orange
    • orange_10
    • orange_4

How to i add a custom style_formats with using data from the database on tinymce? (For ASP.NET MVC)

I use TinyMCE editor. And i want to create a custom inline styles for a span tag. But style datas should come from the database. In this way the data can be obtained.

    $(document).ready(function () {

        $.ajax({
            type: "POST",
            url: '@Url.Action("GetFormats", "Editor")',
            dataType: "json",
            success: function (formats) {
                $.each(formats, function (index, format) {
                    // Datas from database
                });
            }
        });
    });

and define tinymce

    tinymce.init({           
    selector: "textarea",
        theme: "modern",
        plugins: [
            "advlist autolink lists link image charmap print preview hr anchor pagebreak",
            "searchreplace wordcount visualblocks visualchars code fullscreen",
            "insertdatetime media nonbreaking save table contextmenu directionality",
            "emoticons template paste textcolor colorpicker textpattern imagetools"
        ],
        toolbar1: "insertfile undo redo | styleselect formatselect fontselect fontsizeselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media",
        toolbar2: "cut copy paste | searchreplace | print preview removeformat | forecolor backcolor emoticons",

        image_advtab: true,

        style_formats: [
        {
            title: 'My_Style_Combo', inline: 'span', styles: { color: 'rgb(0, 0, 255)', fontFamily: 'comic sans ms,cursive', fontSize:'12px',textDecoration:'underline' } 
        }
       //------> How can I integrate my each data here like this format type?
        ]

    });

I'm sorry for my bad English if you have difficulty in understanding.

I hope it has been a true expression. Thank you in advance for your answers.

Recursive Fortran function return array?

I am relatively new to Fortran (using 90), and haven't been able to find any literature answering this question, so I thought I would ask here on SO: I am trying to write a recursive function that will return an array.

My end goal was to write my own FFT in Fortran without going through the C fftw and using the "C to Fortran" package; I understand there are ways of doing this without using a recursive function, but I would still like to know if a recursive function is able to return an array.

As an exercise, I tried to write a program that takes in a natural number, recursively computes the Fibonacci sequence and returns a list of the Fibonacci numbers indexed up to the argument integer. Using the same algorithm, I wrote this function in Matlab and it works, but there is a semantic error when writing in Fortran 90:

recursive function Fibbo(l)
    integer, INTENT(IN) :: l
    integer, dimension(l)  :: x

    integer, dimension(l) :: Fibbo

    if ( l == 1 ) then
        x = 1
    else if ( l == 2 ) then
        x(1) = 1
        x(2) = 1
    else
        x(1:l-1) = Fibbo(l-1)
        x(n) = x(l-1) + x(l-2)
    end if

Fibbo = x  
end function

It will compile just fine, and no problems except for the output: (when trying to call ell = 3)

Enter an integer:
3
 -1610612736
  1342177280
           0

There is a different output each time, and with an out like that I am guessing there is an issue with memory allocation, or something like that, but like I said I cannot find any literature online addressing recursive functions returning arrays. Perhaps it cannot be done?

Any help would be great, thank you so much for your time!

P.S. It will output the correct list--i.e., 1, [1 1]--when calling Fibbo(1), Fibbo(2), rest.

EDIT: P.P.S. If it matters, I am compiling with gfortran, in Yosemite