نمایش نتایج 1 تا 7 از 7

نام تاپیک: Global چیست؟

  1. #1

    Global چیست؟

    دوستان! این GLOBAL که می نویسن و بعدشم چند تا متغیر چه می کنه؟!
    کتابشو دارما! ولی هر چی گشتم چیزی در موردش پیدا نکردم.
    اگه با مثال توضیح بدید که دیگه خیلی لطف کردید!

    ممنون!

  2. #2
    . آواتار oxygenws
    تاریخ عضویت
    دی 1382
    محل زندگی
    تهران/مشهد
    پست
    6,333
    ایمیل من
    سایت من

    عضویت در جامعه‌ی اهدای عضو

    Direct PGP key: http://tinyurl.com/66q5cy
    PGP key server: keyserver.ubuntu.com
    PGP name to search: omidmottaghi

  3. #3

    The global keyword
    First, an example use of global:

    Example 7-1. Using global

    <?php
    $a = 1;
    $b = 2;

    function Sum()
    {
    global $a, $b;

    $b = $a + $b;
    }

    Sum();
    echo $b;
    ?>



    The above script will output "3". By declaring $a and $b global within the function, all references to either variable will refer to the global version. There is no limit to the number of global variables that can be manipulated by a function.

    A second way to access variables from the global scope is to use the special PHP-defined $GLOBALS array. The previous example can be rewritten as:

    Example 7-2. Using $GLOBALS instead of global

    <?php
    $a = 1;
    $b = 2;

    function Sum()
    {
    $GLOBALS["b"] = $GLOBALS["a"] + $GLOBALS["b"];
    }

    Sum();
    echo $b;
    ?>



    The $GLOBALS array is an associative array with the name of the global variable being the key and the contents of that variable being the value of the array element. Notice how $GLOBALS exists in any scope, this is because $GLOBALS is a superglobal. Here's an example demonstrating the power of superglobals:

    Example 7-3. Example demonstrating superglobals and scope

    <?php
    function test_global()
    {
    // Most predefined variables aren't "super" and require
    // 'global' to be available to the functions local scope.
    global $HTTP_POST_VARS;

    echo $HTTP_POST_VARS['name'];

    // Superglobals are available in any scope and do
    // not require 'global'. Superglobals are available
    // as of PHP 4.1.0
    echo $_POST['name'];
    }
    ?>




    با توجه به امکانات شی گرایی موجود ازش استفاده نکنی راحت تری

    RTFM
    منظور امید راهنمای PHP است.حتما دانلودش کن

    http://www.php.net/download-docs.php
    Artists use lies to tell the truth while politicians use them to cover the truth up

  4. #4
    من کتاب php4 professional رو گرفتم و توش از این چیزا زیاد استفاده کرده. هر چی هم گشتم توش مطلبی در این مورد پیدا نکردم. فقط بگید چی کار می کنه؟ کتابرو دانلود کرده بودم!

  5. #5
    . آواتار oxygenws
    تاریخ عضویت
    دی 1382
    محل زندگی
    تهران/مشهد
    پست
    6,333
    لطفا نمونه کد رو اینجا بنویس.
    ایمیل من
    سایت من

    عضویت در جامعه‌ی اهدای عضو

    Direct PGP key: http://tinyurl.com/66q5cy
    PGP key server: keyserver.ubuntu.com
    PGP name to search: omidmottaghi

  6. #6
    بهت اجازه میده از یک متغییر در هر جایی استفاده کنی کافیست زمان استفاده کلمه کلیدی global رو پشتت بذاری.کد های بالا رو بخون متوجه میشی
    Artists use lies to tell the truth while politicians use them to cover the truth up

  7. #7
    هوتن عزیز ازت خیلی متشکرم!
    از آقای راد هم که می خواستن کد من رو بررسی کنن متشکرم! حالا که جواب کامل اومده دیگه زحمت نمی دیم!

تاپیک های مشابه

  1. کارباglobal.asx
    نوشته شده توسط h.alizadeh در بخش ASP.NET Web Forms
    پاسخ: 5
    آخرین پست: پنج شنبه 08 شهریور 1386, 15:53 عصر
  2. خطای فایل global
    نوشته شده توسط brida_kh در بخش ASP.NET Web Forms
    پاسخ: 5
    آخرین پست: شنبه 23 تیر 1386, 13:07 عصر
  3. متغیر Global
    نوشته شده توسط emad4000 در بخش C#‎‎
    پاسخ: 2
    آخرین پست: دوشنبه 09 مرداد 1385, 15:16 عصر
  4. متغیر Global و انتخاب چاپگر
    نوشته شده توسط only_crystal_reports در بخش گزارش سازی با Crystal Report
    پاسخ: 5
    آخرین پست: چهارشنبه 10 اسفند 1384, 00:27 صبح

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •