Cainiao: How does php define an array of file scopes?

Source: Internet
Author: User
Tags php define
Cainiao: How does php define an array of file scopes?
global $param_array = array('P', 'Q', 'CR', 'LT', 'TC,M1', 'TC,M2', 'RI,M1', 'RI,M2');

The display syntax is incorrect. how can this array have a file scope?
Or is the file scope of an array impossible?


Reply to discussion (solution)

What does file scope mean?

Global cannot be used that way. you can check the manual.

What does file scope mean?

Global cannot be used that way. you can check the manual.



Sorry, I don't know much about php.
What is the scope of the script?
For example:
If array a is defined in a. php, its scope is a. php. all functions can access this array.
But it cannot be accessed in B. php.

No special definition
1. define an array
$ A = array (1, 2, 3, 4, 5)

So its scope is in this file, all functions can be accessed.

Defined in a. php, the array is a global variable by default, which can be used directly outside the function. the function must declare global $ a before it can be used.

 

$param_array = array('P', 'Q', 'CR', 'LT', 'TC,M1', 'TC,M2', 'RI,M1', 'RI,M2');function local(){global $param_array;print_r($param_array);}class localclass{function run(){global $param_array;print_r($param_array);}}print_r($param_array);local();$obj = new localclass();$obj->run();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.