how to call function to function

how to call from function A() to B()…i can’t print out any result from the php script below…Please do help…urgent

<?php function A(){ $ds= array( array(1,11,5), array(2,6,7), array(3,13,9), array(12,7,16), array(14,3,25), array(19,18,22), array(23,13,29), array(24,4,28) ); } function B(){ $ds=$shop; for($i = 0; $i < 3; $i++){ for($j = 0; $j < 4; $j++) print $ds[$i][$j] . "
"; } } ?>

First of all, you are only defining your functions here. You are not really calling them.

Not sure what you are trying to get from Function A into Function B (or the reverse) but the only thing the 2 functions seem to have in common is the variable of $ds. You should read up on the SCOPE of variables. Variables are NOT by default accessible outside the function they are called in. So the Variable of $ds in function A is a different variable than $ds in Function B.

You can get the results of one in to another by using the using a return from within the function.

For example Inside Function A you define an array. You want to use it in B. The last statement in Function A should be return $ds;
In function B you want to use the results, you can then call it by using a statement $ds = A();

Lastly please note that you are assigning an apparently empty value ($shop) to the $ds which you are now trying to manipulate and print out, however there is nothing in there to manipulate.

I hope this helps.

hi thanks for help dude. i do understand wat u mean but yet there is no print result come out. it seem like the function B still can’t call $ds from function A. Hope can hear from u soon^^

Below is modified example:

<?php function A(){ $ds = array( array(1,11,5), array(2,6,7), array(3,13,9), array(12,7,16), array(14,3,25), array(19,18,22), array(23,13,29), array(24,4,28) ); return $ds; } function B(){ $ds = A(); for($i = 0; $i < 8; $i++){ for($j = 0; $j < 3; $j++) print $ds[$i][$j] . "
"; } } ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service