1

i want to do this type

in my form i have check box array and the function i want to call as the size of check box array, now all is ok simple one time calling.

but i want to call the function as above, and store the function return value in one array

as function return array so i want to do like this

for user id 1->callfunction return array
user id 2->callfunction return array .... ....

i have try to used the array_push but i does not get any result

here is my code

$track = array();

for($i=0;$i<sizeof($usr);$i++)
        {
            if (!empty($start) and !empty($end))
            {

                $track_e = $tracker->getProjectTrack($id, $usr[$i], $taski, $start, $end);

                //$track = $tracker->getProjectTrack($id, $usr, $taski, $start, $end);
            }

            $track=array_push($track,$track_e);

        }
1
  • 2
    Please clearify the question. What does the input array look like? What does $tracker->getProjectTack() do? And what you do expect $track to look like after the for loop. Commented Jun 26, 2010 at 7:28

3 Answers 3

2

if you want to go through array, use foreach

$track = array();
if (!empty($start) and !empty($end)){  
 foreach ($usr as $u){
  array_push($track,$tracker->getProjectTrack($id, $u, $taski, $start, $end);
 }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanx it works but it not added element in desire way like this
1

Solution:

$track=array_push($track,$track_e);

array_push doesn't return an array; it returns the new number of elements in the array, modifying the array it receives as an argument in-place. It's actually much easier to just write:

$track []= $track_e;

Suggestion:

for($i=0;$i<sizeof($usr);$i++) {
    # ...
    $track_e = $tracker->getProjectTrack($id, $usr[$i], $taski, $start, $end);

Why not simplify the process of indexing $usr and counting the number of elements in it like so:

foreach ($usr as $usr_elem) {
    # ...
    $track_e = $tracker->getProjectTrack($id, $usr_elem, $taski, $start, $end);

Comments

0

Array ( [0] => Array ( [0] => 5 ) [1] => Array ( [0] => 6 ) [2] => Array ( [0] => 7 ) )

instead of this it returns

Array ( [0] => Array ( [0] => Array ( [0] => 7 ) ) [1] => Array ( [0] => Array ( [0] => 9) ) )

something like that

so i want to return it in as same first one.

2 Comments

Please do not supply additional information to your question as an answer. SO does not work like a forum. Please use the Edit link below your question
How come you want to have an array with [0] elements that simply point to a one element array? Wouldn't the first one make a little bit more sense? Please clarify how exactly you want these arrays to be structured with some more examples and more importantly, WHY it needs to be like that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.