Newcomers have two questions about php

Source: Internet
Author: User
The newcomer has two questions about php. he first entered php and found a video tutorial. after reading the book for a few days, he planned to learn it; because you are the kind of things that you don't understand and understand; however, I threw my book aside & nbsp; I couldn't do it myself & nbsp; so I just wanted to find a video to watch. it's faster than reading a book. new people have two questions about php.
I found a video tutorial in php for a few days.
I was planning to read and learn
To be honest, you are also somewhat impetuous, because you are the kind of person who doesn't understand, understands, or understands.
So when I read a book, I think everything in the book will look like myself, but I can't do anything, so I just want to get a video to watch it faster than the book.
The first question is about the array
In the video, $ arr [0] (called an index array) $ arr ['XX'] (called an associated array)
It is more efficient to use indexes than to use keys, but in php, according to the usage feeling, $ arr [0] $ arr ['XX'] seems like a hash structure. there is no difference between the two. no matter the number or other values are used as the key, so the efficiency of the number is higher than that of other values, and it is not a direct offset.
Therefore, we recommend that you use the fetch_row function whenever possible during database query. In fact, I also want to know the difference between the function and the fetch_assoc function in addition to the key ,,
The second problem is the direct access to the PHP file in the address bar.
For example, there is a PHP file with only one class I wrote. I don't want to access this file from the address bar. baidu. I can see that many of them are define. in the PHP file, I can determine whether or not define is used. what? However, although this seems to have solved the problem, it seems a little strange that the file is actually accessed.
------ Solution --------------------
1. there is only a key difference between fetch_row and fetch_assoc.
2. define A. htaccess file in the directory to restrict access to the file.
------ Solution --------------------
1. php arrays are all hash arrays, and there is no subscript due to association key issues
Your tutorial is incorrect.
2. php code always needs to be loaded before running. in the php program, you can determine whether to allow the execution of other parts.
------ Solution --------------------
About the second point:

The script must be run first. If you are worried that a script is directly called by a third party who knows the address, the better method is:

All published scripts are stored in/var/www/site1/web, but all those that do not want to be published are stored in/var/www/site1/include. Set a. htaccess file for the include directory to restrict access.

In addition, the upstairs statement: Php uses include to organize files.This statement is too old. Today's trend is the use of Composer

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.