473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

function not returning values into my array

130 100+
hello all,

i made a function that supposed to feed dual array

my problam is that the varibal is visibale inside the function but when it return it dies with it. :(

thats what i want the function to return
Expand|Select|Wrap|Line Numbers
  1. function sort($n,$mytimestemp,$mytoatl){
  2. $ts[$n][0]=$mytimestemp;
  3. $total[$n][0]=$mytotal;
  4. return;
  5. }
then when i want to use the data i get notice that its empty
Expand|Select|Wrap|Line Numbers
  1. print_r($ts);
  2. print_r($total);
i know the first time i use $ts and $total is inside the function
but even if i first put them at the top of the code or right affter the functin or righr before the function still they dont get updated with $mytimestemp and $mytotal.

i try to declare it like that :
A:
Expand|Select|Wrap|Line Numbers
  1. $ts;
  2. $total;
B:
Expand|Select|Wrap|Line Numbers
  1. $ts = array();
  2. $total = array();
C:
Expand|Select|Wrap|Line Numbers
  1. global $ts;
  2. global $total;
is it because its array in array?
Jan 24 '08 #1
2 1168
nomad
664 Expert 512MB
hello all,

i made a function that supposed to feed dual array

my problam is that the varibal is visibale inside the function but when it return it dies with it. :(

thats what i want the function to return
Expand|Select|Wrap|Line Numbers
  1. function sort($n,$mytimestemp,$mytoatl){
  2. $ts[$n][0]=$mytimestemp;
  3. $total[$n][0]=$mytotal;
  4. return;
  5. }
then when i want to use the data i get notice that its empty
Expand|Select|Wrap|Line Numbers
  1. print_r($ts);
  2. print_r($total);
i know the first time i use $ts and $total is inside the function
but even if i first put them at the top of the code or right affter the functin or righr before the function still they dont get updated with $mytimestemp and $mytotal.

i try to declare it like that :
A:
Expand|Select|Wrap|Line Numbers
  1. $ts;
  2. $total;
B:
Expand|Select|Wrap|Line Numbers
  1. $ts = array();
  2. $total = array();
C:
Expand|Select|Wrap|Line Numbers
  1. global $ts;
  2. global $total;
is it because its array in array?
What are you trying to return. Possible a $ value
your print proved that.
Jan 24 '08 #2
Amzul
130 100+
silly me i got it now, affter looking around i notice that
when calling to a functiuon i need to send it the refrence of the array

so it should be like that :

Expand|Select|Wrap|Line Numbers
  1. function sort($n,$mytimestemp,$mytoatl,$ts,$total){
  2. $ts[$n][0]=$mytimestemp;
  3. $total[$n][0]=$mytotal;
  4. return;
  5. }
and the call is:
Expand|Select|Wrap|Line Numbers
  1. sort($n,'2008-01-24','200',&$ts,&$total);
Jan 25 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Krackers | last post by:
How do you write a function which returns a reference to an array. I can only get a function to return a copy of the array itself. I've had a look at some other threads in this group an the return...
17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
41
by: Materialised | last post by:
I am writing a simple function to initialise 3 variables to pesudo random numbers. I have a function which is as follows int randomise( int x, int y, intz) { srand((unsigned)time(NULL)); x...
8
by: Tweaxor | last post by:
Hey, I was trying to figure out was it possible in C to pass the values in an array from one function to another function. Is the possible in C? ex. y is the array that holds seven values If...
1
by: Guha | last post by:
I have a problem with returning a 2D array using a function which is called in main(). The piece of the code is given below. This is a test code only. #include"stdio.h" #include"alloc.h" ...
1
by: vijay.gandhi | last post by:
Hello, I have created a function in C++/CLI which was exported as a .DLL to be used in VB .NET. I have been having some problems (I think it has to do with the right syntax) with parameter...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
160
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
5
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.