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);
开发者_如何学Python }
$track=array_push($track,$track_e);
}
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);
}
}
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);
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.
精彩评论