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.