my code is below which is not working <?php $recwidth=550; $recheight=300; $canvas = imagecreate($recwidth, $recheight); $white = imagecolorallocate($canvas, 255, 255, 255); $black = imagecolorallocate($canvas, 0, 0, 0); function rec($startx,$starty,$endx,$endy){ imagerectangle($canvas, $startx, $starty, $endx, $endy, $black); } rec(20,100,200,200); // Output and free from memory header('Content-Type: image/jpeg'); imagejpeg($canvas); imagedestroy($canvas); ?> Please Help me someone
function rec($startx,$starty,$endx,$endy){ global $canvas; // <-------- here imagerectangle($canvas, $startx, $starty, $endx, $endy, $black); }
Thank u so much gapz101 It was finally solved by u. This will help me to finalize my thesis. But little correction with u. function rec($startx,$starty,$endx,$endy){ global $canvas; // <-------- here lobal $black; // <-------- new here imagerectangle($canvas, $startx, $starty, $endx, $endy, $black); } Would u please tell me when and why we use global. Advantages and Disadvantages