PHP and php tutorials

Source: Internet
Author: User

PHP and php tutorials

The following method is worth getting the array directly before 5.4:

<?php    $str = 'a;b;c;d';    list($value) = explode(';',$str);    echo $value;

  

Result:

But what does Array derenferencing of 5.4 mean? As follows:

<?php    $str = 'a;b;c;d';    $value = explode(';',$str)[0];    echo $value;

  

The result is the same as:

It is actually very simple, but some problems may occur during our use. For example

<?php    class Example{                private $value = [];                public function getValue(){                        return $this->value;                    }    }        $example = new Example;        $example->getValue()['test'] = 'test';        echo $example->getValue()['test'];

  

The following error occurs:

Notice: Undefined index: test in D:\Php\xampp\htdocs\test\PHP - 5.x\example.php on line 17

The above code obfuscated the return value and return reference. In PHP, unless you specify the returned reference, the PHP array returns a value, that is, copying an array. Therefore, the code above assigns a value to the returned array, which is to assign a value to the copy array instead of the original array.

 

The following is a possible solution: output the copied array instead of the original array:

$vals = $config->getValues(); $vals['test'] = 'test'; echo $vals['test'];  //test

  

If you just want to change the original array, that is, to reverse the array reference, you just need to display the specified return reference.

<?php    class Example{                private $value = [];                public function &getValue(){                        return $this->value;                    }    }        $example = new Example;        $example->getValue()['test'] = 'test';    echo $example->getValue()['test'];

Output in the above example: test

 


What is the PHP file? How can I open it?

You downloaded a link file similar to asp, not your original file!
It must be executed on the server side before it can reach the correct one. Therefore, it is best to click to enter the webpage to obtain the correct suffix, for example, the suffix is similar to rar, and then use it. If it cannot be obtained, it may be a problem with the server. Inaccessible

PHP is a server-side HTML-embedded script Description Language. Its strongest and most important feature is its database integration layer. using it to complete a Web page containing database functions is incredibly simple. In HTML files, PHP scripts (similar to Perl or c) can be referenced using special PHP labels, so that the web page Creator does not have to rely entirely on HTML to generate webpages. Because PHP is executed on the server side, the client cannot see the PHP code. PHP can complete any task that CGI scripts can do, but its function depends on its compatibility with various databases. In addition to HTTP Communication, PHP can also use the IMAP, SNMP, NNTP, and POP3 protocols.

What is the PHP file? How can I open it?

You downloaded a link file similar to asp, not your original file!
It must be executed on the server side before it can reach the correct one. Therefore, it is best to click to enter the webpage to obtain the correct suffix, for example, the suffix is similar to rar, and then use it. If it cannot be obtained, it may be a problem with the server. Inaccessible

PHP is a server-side HTML-embedded script Description Language. Its strongest and most important feature is its database integration layer. using it to complete a Web page containing database functions is incredibly simple. In HTML files, PHP scripts (similar to Perl or c) can be referenced using special PHP labels, so that the web page Creator does not have to rely entirely on HTML to generate webpages. Because PHP is executed on the server side, the client cannot see the PHP code. PHP can complete any task that CGI scripts can do, but its function depends on its compatibility with various databases. In addition to HTTP Communication, PHP can also use the IMAP, SNMP, NNTP, and POP3 protocols.

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.