Discussion:
foreach with array key value
(too old to reply)
alex
2015-07-11 19:00:23 UTC
Permalink
In this function

function fty($op, $t= array())
{
...
}


inner with a print_r of $t
I have this
Array (
[0] => 2
[1] => 10
)


I need to call same function more time with a cicle
but not know how to do

only so work:

for test I created one my array with [0] => 2 and [1] => 10
but work only if I write so:

$n=0;
foreach ($myarr as $key_g => $t_g) {
$app[$n++] = $t_g;
};
foreach ($myarr as $key_g => $t_g) {
fty($op, $app);
};

how can call the function directly not using the first loop;
loop that reconstructs only the pair key value thet I already have
alex
2015-07-11 19:25:39 UTC
Permalink
Post by alex
In this function
function fty($op, $t= array())
{
...
}
inner with a print_r of $t
I have this
Array (
[0] => 2
[1] => 10
)
I need to call same function more time with a cicle
but not know how to do
for test I created one my array with [0] => 2 and [1] => 10
$n=0;
foreach ($myarr as $key_g => $t_g) {
$app[$n++] = $t_g;
};
foreach ($myarr as $key_g => $t_g) {
fty($op, $app);
};
how can call the function directly not using the first loop;
loop that reconstructs only the pair key value thet I already have
think so
foreach ($myarr as $key_g => $t_g) {
Post by alex
fty($op, $myarr);
};
BAHC
2015-09-22 18:47:26 UTC
Permalink
$myarray = [2, 10];
$app = array_values($myarray);
$i = count($myarray);
while($i) {
fty($op, $app);
$i--;
}

function fty($op, $app){ ...do your operation with $app array... }
Post by alex
In this function
function fty($op, $t= array())
{
...
}
inner with a print_r of $t
I have this
Array (
[0] => 2
[1] => 10
)
I need to call same function more time with a cicle
but not know how to do
for test I created one my array with [0] => 2 and [1] => 10
$n=0;
foreach ($myarr as $key_g => $t_g) {
$app[$n++] = $t_g;
};
foreach ($myarr as $key_g => $t_g) {
fty($op, $app);
};
how can call the function directly not using the first loop;
loop that reconstructs only the pair key value thet I already have
Loading...